Perform a function on a sequence of Variables

2 views (last 30 days)
how does one perform the same function on a sequence of variables?

Answers (1)

Image Analyst
Image Analyst on 31 Mar 2015
Just call the function, passing in each of the variables.
out1 = YourFunction(var1);
out2 = YourFunction(var2);
out3 = YourFunction(var3);
out4 = YourFunction(var4);
out5 = YourFunction(var5);
  2 Comments
Marcel Kroschk
Marcel Kroschk on 31 Mar 2015
i have several thousand variables is there a script to do them all in sequence like they are numbered?
Image Analyst
Image Analyst on 31 Mar 2015
They're in an array, right. Surely you don't have several thousand variables all with unique names ? That would be stupendously unwise.
for k = 1 : numel(m)
out(k) = YourFunction(m(k));
end

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!