- more efficient
- less error-prone
- without hideous side-effects
- easy to code, read and maintain
- ...
Is there the more elegant way to do this?
2 ビュー (過去 30 日間)
古いコメントを表示
I would like to call arguments of function from a string or cell array. For example, this code works as I want:
function testarg()
a=1;b=2;c=3;
m='a,b,c';
eval(['myfun(',m,')']);
function myfun(a,b,c)
a
b
c
Is there another way to do this? Say, without using eval ?
2 件のコメント
Jos (10584)
2014 年 1 月 29 日
Just a tip: whenever you found yourself using eval, you will be 99.999% sure that there is a way to do it some other way without using eval that is:
eval(char('chro''&HB@MCNVHSGNTSDU@K &('+1))
採用された回答
Matt J
2014 年 1 月 28 日
function myfun(varargin)
varargin{:}
その他の回答 (1 件)
Amit
2014 年 1 月 28 日
function testarg()
a=1;b=2;c=3;
abc(a,b,c)
function abc(a,b,c)
a
b
c
This wil ldo just fine.
4 件のコメント
参考
カテゴリ
Help Center および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!