How to run m-files(main function is variable) with Matlab code?
이전 댓글 표시
The values of variable have been got by excel file. And also known the name of m-file for the main function. I want to call this main function with variable or others instead of type the function name directly.
for example
below inputs already defined.
a1=1;
a2=2;
a3=5;
b1=6;
b2=9;
...
Question is how to run the m-file with above inputs value? i try to use
run myfun
but error happen due to variable a1, a2, ...b2 don't be assigned with above values.
I know we can use below comen code. but it is not what I want because there are many different m-file. I want to make a general coe to replace below code. I don't want to copy below code flow and past it every time for too many m-file.
[x1,x2,x3]=myfun(a1 a2 a3 b1 b2 )
below function is defined in myfun.m
function [x1,x2,x3]=myfun(a1 a2 a3 b1 b2 )
x1=a1+a2,
x2=a3+a2;
x3=b1+b2+b3;
end
댓글 수: 3
Rik
2020년 5월 14일
Why don't you want to do this? With what would you like to replace it? The beauty of Matlab is that you don't need to know what variable names a function is using, just the syntax.
W. Feng
2020년 5월 19일
Rik
2020년 5월 19일
It looks to me like your numbered variables should be arrays instead. Otherwise you would have to do something useful with 30k input variables. That isn't impossible, but it is not likely to be what you need.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!