Is it possible to run a set of scripts through a for loop or is there a different method I could use?

2 次查看(过去 30 天)
I have several scripts that run a bunch of formulas and give a number as output but I need to run them while changing one of the input variables several times.
Say I have script_1, scrip_2 and script_3 which if ran in order they give number y as an output, a function of variable x.
I have a master scrip which runs everything in order and records number y for one value of variable x which is defined at the beginning of the master script. How can I setup the master script so that it can vary x, say from 1 to 100, run through script_1, scrip_2 and script_3, and record output y?
I was thinking of a for loop like:
x(1) = 1;
for i = 1:100
x(1+i) = x(i) + 1;
script_1;
script_2;
script_3;
end
But the scripts can't be ran in a for loop like that. Is there a way to do this?

采纳的回答

Sheng Chen
Sheng Chen 2019-3-3
script1.m
function y = script1(x)
y = x + 1;
end
script2.m
function y = script2(x)
y = x + 2;
end
script3.m
function y = script3(x)
y = x + 3;
end
master.m
for x = 1 : 10
disp(script1(x));
disp(script2(x));
disp(script3(x));
disp("--------------------");
end
Put these four .m files into the directory and run master.m

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operators and Elementary Operations 的更多信息

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by