passing arguments between function files
Informazioni
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Mostra commenti meno recenti
Anyone know how to allow multiple files as input for one function file?
4 Commenti
Jan
il 30 Giu 2012
Please explain any details of your problem.
anna
il 2 Lug 2012
Jan
il 3 Lug 2012
Do you mean something like: Z = max(sin(0.2), cos(0.3))? max, sin and cos are functions also.
Usually it helps to understand the problem, if you post, what you have tried so far.
Walter Roberson
il 24 Ago 2012
(No obvious reason to close this question, but one of the Answers should be Accepted.)
Risposte (2)
Image Analyst
il 30 Giu 2012
Modificato: Image Analyst
il 3 Lug 2012
% Define a function to take mulitple filenames and return multiple outputs.
function [output1 output2 output3] = yourFunction(filename1, filename2, filename3)
4 Commenti
anna
il 2 Lug 2012
Image Analyst
il 3 Lug 2012
Why not? That's how you define a function to take multiple inputs and return multiple outputs. You call it almost the same way, just don't use the function word:
% Call the function.
[output1 output2 output3] = yourFunction(filename1, filename2, filename3);
anna
il 4 Lug 2012
Image Analyst
il 15 Lug 2012
If funcx and funcy both return an x and a y, how about
[x1 y1] = funcx();
[x2 y2] = funcy();
zOutput = funcz(x1, y1, x2, y2);
or using an alternate interpretation of your wording:
x = funcx();
y = funcy();
zOutput = funcz(x, y);
(This is what Walter said except that I'm capturing the outputs into arrays in the main program first before I pass them into funcz.)
Walter Roberson
il 3 Lug 2012
Z = funcZ( funcX(), funcY() );
disp(Z);
function Z = funcZ( X, Y )
Z = .... appropriate code ...
end
function X = funcX()
X = .... appropriate code ...
end
function Y = funcY()
Y = .... appropriate code ...
end
2 Commenti
anna
il 4 Lug 2012
Walter Roberson
il 15 Lug 2012
You said that X is an output of funcX and Y is an output of funcY, so you should not be passing X or Y into funcX and funcY
Put the following into testfuncZ.m :
Z = funcZ( funcX(), funcY() );
disp(Z);
Then put the funcZ code into funcZ.m and the funcX code into funcX.m and the funcY code into funcY.m . Invoke it all by giving the command
testfuncZ
Questa domanda è chiusa.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!