How can I set multiple variables to the same initial value efficiently?

17 ビュー (過去 30 日間)
Anteneh Zewdu
Anteneh Zewdu 2018 年 12 月 6 日
コメント済み: madhan ravi 2018 年 12 月 13 日
I hate using the following way of defining variables;
a= 5, b=a, c=a, d=a, etc
I have a lot of variable taking the same intial value, how can do it efficiently?
Thanks in advance!
  1 件のコメント
Stephen23
Stephen23 2018 年 12 月 6 日
"I have a lot of variable taking the same intial value, how can do it efficiently?"
Simple: store your data in one array.
Having "a lot of variables" is a sign that you should be using arrays anyway.

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

採用された回答

madhan ravi
madhan ravi 2018 年 12 月 6 日
[a,b,c,d]=deal(5)

その他の回答 (1 件)

Anteneh Zewdu
Anteneh Zewdu 2018 年 12 月 6 日
I found the answer from a friend
[a, b, c, d] = deal(5)
  3 件のコメント
Anteneh Zewdu
Anteneh Zewdu 2018 年 12 月 13 日
Madhan brother, I haven't seen your answer at the time. Thanks for the help.
madhan ravi
madhan ravi 2018 年 12 月 13 日
No problem , anytime :)

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

カテゴリ

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

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by