How to convert a string to a variable useable in a script?

1 回表示 (過去 30 日間)
Med Aymane Ahajjam
Med Aymane Ahajjam 2016 年 7 月 18 日
コメント済み: Med Aymane Ahajjam 2016 年 7 月 19 日
Hello, So The idea is to construct a string of the name of a variable (network class) that already exists in the workspace, and then calling that string for a specific input would output the same result as if it was done directly by the original variable.. Here is my code: Z11='haar_net_scg_in1_2obsrv'; yfit11 = eval(Z11(Ind_vald')); So the variable is called haar_net_scg_in1_2obsrv it's a network (ANN) and I want to use it to predict the class of an iput Ind_vald' . but I always get this error: Subscript indices must either be real positive integers or logicals. Knowing if I apply the network directly I get the results.. I really need this to work because I have a for loop with changing network names that I need to make them predict the class of some inputs Thanks

採用された回答

jgg
jgg 2016 年 7 月 18 日
編集済み: jgg 2016 年 7 月 18 日
I think you're like 99% of the way there.
Z11='haar_net_scg_in1_2obsrv';
yfit11 = eval(strcat(Z11,'(Ind_vald)');
This should work as long as it's well-formed. You may need to transpose the Ind_vald item beforehand if you need it to be transposed in the expression.
  1 件のコメント
Med Aymane Ahajjam
Med Aymane Ahajjam 2016 年 7 月 19 日
Hey there jgg, thank you for your quick answer, it worked perfectly!
:D You're the best!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by