1

Let's say I have some function import_data() and inside of this function I am creating 2 variables: response_values and file_to_get

file_to_get = uigetfile({'*.csv*'}, 'Select the CSV File',...
'\\pfile01thn\bbruffey$\My Documents\analysis data\full files\...
Raw Stats Data full file only');

response_values = zeros(numel(C),numCols);
for i=1:numel(C)
    v = textscan(C{i}, '%s', 'Delimiter',',');
    v = str2double(v{1}(4:end));
    response_values(i,1:numel(v)) = v;
end

I then need these variables passed into another function MS_Banding_Streaking()

How could this be done? (I'm using globals at the moment which is extremely bad practice.

1
  • 2
    Unless I misunderstood the question, can't you just assign the variables you want as the outputs of input_data() and then pass them to MS_Banding_Streaking in the standard way as in my answer? Commented Aug 2, 2012 at 18:25

2 Answers 2

2

Something like

file import_data.m

function response_values, file_to_get = import_data()

file_to_get = uigetfile({'*.csv*'}, 'Select the CSV File',...
'\\pfile01thn\bbruffey$\My Documents\analysis data\full files\...
Raw  Stats Data full file only');

response_values = zeros(numel(C),numCols);
for i=1:numel(C)
    v = textscan(C{i}, '%s', 'Delimiter',',');
    v = str2double(v{1}(4:end));
    response_values(i,1:numel(v)) = v;
end

file mainfunc.m

% Stuff before
[vals, filegot] = import_data()
MS_Banding_Streaking(filegot, vals)
% Stuff after
Sign up to request clarification or add additional context in comments.

3 Comments

@BenB.: ins was a generic variable name in case your import_data function was to take inputs... if you don't need it just remove it, i.e. function response_values, file_to_get = import_data() ...
oh okay, i do have options that i have implemented for plotting but I'd remmoved them thinking i needed this haha. okay
@BenB. - I modified my code to reflect the fact that you didn't need any inputs to input_data
1

Just simply write the two functions in the same .m file

function import_data()    
file_to_get = uigetfile({'*.csv*'}, 'Select the CSV File',...
'\\pfile01thn\bbruffey$\My Documents\analysis data\full files\...
Raw  Stats Data full file only');

response_values = zeros(numel(C),numCols);
for i=1:numel(C)
    v = textscan(C{i}, '%s', 'Delimiter',',');
    v = str2double(v{1}(4:end));
    response_values(i,1:numel(v)) = v;
end

MS_Banding_Streaking(response_values, file_to_get);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function MS_Banding_Streaking(resp_value, f2g)
% function body

6 Comments

So since the function import_data() is creating the variable response_values if i understand your example correctly, i should just be able to add it in MS_Banding_Streaking(response_values) and it should work. Right now running my code this way it is telling me that the variable response_values is undefined.
@BenB. You should call MS_Banding_Streaking inside import_data since response_values is created within import_data
Note though that doing this this way means that you can't call MS_Banding_Streaking from anywhere other than this file.
That's the issue I see with this, since i have a main function that is calling both import_data() and MS_Banding_Streaking()
@BenB. actually you can put the MS_Banding_Streaking function in a seperate file, as long as it's in the same directory as the main function file and the import_data() file, you should be able to call it in both main function and the import_data().
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.