How to call m-file

2 次查看(过去 30 天)
Ahmed Hassaan
Ahmed Hassaan 2012-4-4
Hello,
I have an if condition in the intro of my code , and there are three cases i want to do like this in matlab
(example )case 1 call mfile1,
case 2 call mfile2,
case3 call mfile3
thanks :)

采纳的回答

Walter Roberson
Walter Roberson 2012-4-4
if value == 1
mfile1;
elseif value == 2
mfile2;
else
mfile3;
end
Or alternately,
switch value
case 1: mfile1;
case 2: mfile2;
case 3: mfile3;
end
Or another way:
fn = {@mfile1, @mfile2, @mfile3);
fn{value}();

更多回答(1 个)

Wayne King
Wayne King 2012-4-4
How about a switch
switch test
case 'value1'
mfile1()
case 'value2'
mfile2()
otherwise
mfile3()
end
You have not specified what the condition is, e.g. numeric, string, etc.

类别

Help CenterFile Exchange 中查找有关 Software Development Tools 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by