フィルターのクリア

Way to pass to a function a random variable based on array

1 回表示 (過去 30 日間)
Chris
Chris 2012 年 3 月 22 日
I have a list of variables in my workspace as a string array. I want to call a function to test every combo
Unfortunately when i run as it currently is it passes the string of the varialbe name and not the variable in my workspace. I have tried using the eval command however I can't have the eval command work in a parfor loop. Unfortunately without parfor it is very slow to test.
parfor i = 1:10
for j = i:10
testprocedure(VarArray(i,1),VarArray(j,1))
end
end

採用された回答

Walter Roberson
Walter Roberson 2012 年 3 月 22 日
I would suggest using a structure array in your case.
testprocedure( VarStruct.(VarArray{i}), VarStruct.(VarArray{j}) )
  1 件のコメント
Oleg Komarov
Oleg Komarov 2012 年 3 月 22 日
I am seriously thinking to resume my post on how people should scale their projects, because inevitably they end up with eval.

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

その他の回答 (1 件)

Chris
Chris 2012 年 3 月 23 日
Thanks, I guess I am a little confused though how to do.
So for example I have an array called TeamNames that contains all of the names of various teams. TeamNames(1,1) is called Bulls which is a variable in my matlab workspace. How do I pass Bulls to my function TestProcedure without using Eval? I want the forloop to loop through all TeamNames and run the test procedure on two teams at a time. Ideally using parfor since it is a lot faster. When I run the testprocedure(TeamNames(i,1),TeamNames,(j,1)) it passes the string of the variable rather than the matlab variable in my workspace. I have to use the eval command to pass however that is not compatible with Parfor so I am stuck.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by