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

19 Ansichten (letzte 30 Tage)
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 Kommentar
Stephen23
Stephen23 am 6 Dez. 2018
"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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

madhan ravi
madhan ravi am 6 Dez. 2018
[a,b,c,d]=deal(5)

Weitere Antworten (1)

Anteneh Zewdu
Anteneh Zewdu am 6 Dez. 2018
I found the answer from a friend
[a, b, c, d] = deal(5)
  3 Kommentare
Anteneh Zewdu
Anteneh Zewdu am 13 Dez. 2018
Madhan brother, I haven't seen your answer at the time. Thanks for the help.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by