How to run 3 script in sequence?

2 次查看(过去 30 天)
I have 3 scripts.
a= 'add.m'
b ='split.m'
c ='find.m'
I want to run those scripts in sequence, how can i do it?
I used the for loop but it didn't work.
d = [ a , b , c]
for i =1: 3
try
run(d(i)
catch
disp (' it does not work')
end
end

采纳的回答

Dyuman Joshi
Dyuman Joshi 2023-11-15
First of all, Never use built-in functions as variable or scripts names.
You should modify the names of the scripts; for e.g. by adding a prefix as I have done below (or a suffix), or change the names entirely.
Second, you need to store the names as strings or cell array of char vectors -
a = 'script_add.m';
b = 'script_split.m';
c = 'script_find.m';
%Check the output of concatenating the names directly
d = [a b c]
d = 'script_add.mscript_split.mscript_find.m'
%First three elements
d(1:3)
ans = 'scr'
%Store in cell array
names = {a, b, c};
for k=1:numel(names)
try
run(names{k})
catch
disp('It does not work')
end
end
  6 个评论
Antonio
Antonio 2023-11-15
They are not defined as a function
Dyuman Joshi
Dyuman Joshi 2023-11-15
Could you attach the files, so I can reproduce the error and provide you with a working solution?

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!