Hello,
how can I pre-define list of variables (e.g. var_1,var_2,...,var_n) that have the same content, for example zeros(100). I thought [var_1,var_2,...var_n]=[zeros(100),zeros(100),...,zeros(100)]; could work, but I was wrong. Any idea is appreciated.
Thank you very much,
Tom

 採用された回答

Amanda Galtman
Amanda Galtman 2011 年 8 月 24 日

0 投票

Try using the deal function:
[var_1, var_2, var_3] = deal(zeros(100));
HTH, Amanda

2 件のコメント

tomas
tomas 2011 年 8 月 24 日
That's it. Thank you Amanda :-)
Jan
Jan 2011 年 8 月 24 日
This is correct, but not optimal for pre-allocation: After DEAL, the variables use shared data copies, which point to teh same memory. If you write to these variables, the sharing link must be released at first. Therefore a direct "var_1=zeros(100); var_2=zeros(100)" is slightly faster. But if it concerns 3 or 50 variables only, this delay can be neglected.

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

その他の回答 (1 件)

bharat suthar
bharat suthar 2020 年 5 月 23 日

0 投票

Which of the following is a pre-defined variable in Matlab?

カテゴリ

ヘルプ センター および File ExchangeQuadratic Programming and Cone Programming についてさらに検索

質問済み:

2011 年 8 月 24 日

回答済み:

2020 年 5 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by