Replace 'eval' for more efficient code

2 ビュー (過去 30 日間)
V B
V B 2015 年 9 月 5 日
編集済み: Stephen23 2023 年 9 月 12 日
I'm trying to simulate some results by conditioning on different sets of variables i.e. the power set of the covariates. In order to label the output, I'm using 'eval' depending on the conditioning set, but this is extremely slow. Is there a better way to do this? I have attached the code.

採用された回答

Stephen23
Stephen23 2015 年 9 月 5 日
編集済み: Stephen23 2023 年 9 月 12 日

その他の回答 (1 件)

the cyclist
the cyclist 2015 年 9 月 5 日
I did not dive deeply into your code, but one thing you are doing (which is common when people resort to using eval) is naming variables pval_1_2, etc.
You can avoid that need by using cell arrays to store variables. For example
pval{1,2} = rand(2,5);
pval(6,7) = rand(3,4);
etc
Here is one of many places on this forum that discusses the problem of naming variables A1, A2, etc.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by