I have trouble understanding the command.

1 回表示 (過去 30 日間)
Kaminosono Shougo
Kaminosono Shougo 2022 年 10 月 15 日
コメント済み: Hiro Yoshino 2022 年 10 月 22 日
I'm having trouble understanding what the command below does, I'd like to know if anyone knows what it does.
for i=1:nset
tty=y(i,:);
index=find(tty>=0);
tx=x(i,index,:);
ty=tty(index);
tpar=mpar(:,i);
command=['[esty seout]=',fun,'(tpar,tx);']; //
eval(command); 
m=length(esty);
predy(i,1:m)=esty;
if(linear == 1);
errory=errory+((esty-ty)*(esty-ty)');
else
findex=find(esty<=0);
esty(findex)=ones(size(findex))/1000000000;
error=20*log10(esty)-20*log10(ty);
errory = errory+error*error';
end
end
I don't know what you are doing with the two sentences in this programme, does anyone know?
command=['[esty seout]=',fun,'(tpar,tx);'];
eval(command); 
  2 件のコメント
Kaminosono Shougo
Kaminosono Shougo 2022 年 10 月 17 日
thank you!
You mean you changed the name of the output variable of the function 'fun', that's clear.
Stephen23
Stephen23 2022 年 10 月 17 日
編集済み: Stephen23 2022 年 10 月 17 日
Do not learn from such badly-written code.
If the code's author had read the Tips section of the EVAL documentation, they would know it is not recommended to include the output arguments in the EVAL call, only the RHS. They could (should) have done that.
And then if they had done a bit more thinking and reading on the topic, they would have known to replace the EVAL with STR2FUNC (which defines a function handle that can be repeatedly called without the performance hit of repeated EVAL calls).
Caecus caeco dux. Sigh.

サインインしてコメントする。

採用された回答

Hiro Yoshino
Hiro Yoshino 2022 年 10 月 15 日
You should have a good understanding on eval by going through this.
What it does here is that
[esty, seout] = fun(tpar,tx);
It seems there is a function named "fun" somewhere and its arguments are tpar and tx.
  5 件のコメント
Bruno Luong
Bruno Luong 2022 年 10 月 22 日
@Hiro That function might be an anonymous function
To be precise FUN must be variable or (anonymous-function that return char ouput argument a string/char that stores the name of the 'anonymous' function so it can be form the command called by EVAL.
So there are two different ways of interpreting your "anonymous function".
Hiro Yoshino
Hiro Yoshino 2022 年 10 月 22 日
@Bruno Luong You're right. That was my fault. Sorry guys but it's good to know that you found the "fun" function somewhere.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by