how to run function for several times with different variables

62 views (last 30 days)
I have something like this:
a=5
b=8
c=9
d=11
%a,b,c and d are function inputs
n=a*0.1:a*0.1:a
for i=1:length(n)
"function"
end
but I need to run function replacing 'a' in 'n' with 'b','c' and 'd' at once and save the data so I can compare it. it is a sensitivity analysis for this function outputs.
  2 Comments
Asliddin Komilov
Asliddin Komilov on 12 Mar 2019
that is too difficult for me, I did it for each variable separately (see below). thank you

Sign in to comment.

Answers (2)

Dennis
Dennis on 5 Mar 2019
In your example you do not need more than one variable:
a=[5 8 9 11];
for i=1:numel(a)
n=a(i)*0.1:a(i)*0.1:a(i);
for k=1:numel(n)
%function
end
end
  2 Comments
Asliddin Komilov
Asliddin Komilov on 12 Mar 2019
thanks, but it gave error inside th function, so I decided to skip it.

Sign in to comment.


Asliddin Komilov
Asliddin Komilov on 12 Mar 2019
Edited: Stephen23 on 12 Mar 2019
I just saved the loop for each variable.
a=5
b=8
c=9
d=11
%a,b,c and d are function inputs
n=a*0.1:a*0.1:a
for i=1:length(n)
"function"
end
save file_a
a=a(end);
clear "function outputs"
%--------------------------
n=b*0.1:b*0.1:b
for i=1:length(n)
"function"
end
save file_b
b=b(end);
clear "function outputs"
%---------------------------
..........
  1 Comment
Stephen23
Stephen23 on 12 Mar 2019
You could save the bother by simply putting your data into one array and using indexing.

Sign in to comment.

Categories

Find more on Data Type Identification in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!