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

17 vues (au cours des 30 derniers jours)
Anteneh Zewdu
Anteneh Zewdu le 6 Déc 2018
Commenté : madhan ravi le 13 Déc 2018
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 commentaire
Stephen23
Stephen23 le 6 Déc 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.

Connectez-vous pour commenter.

Réponse acceptée

madhan ravi
madhan ravi le 6 Déc 2018
[a,b,c,d]=deal(5)

Plus de réponses (1)

Anteneh Zewdu
Anteneh Zewdu le 6 Déc 2018
I found the answer from a friend
[a, b, c, d] = deal(5)
  3 commentaires
Anteneh Zewdu
Anteneh Zewdu le 13 Déc 2018
Madhan brother, I haven't seen your answer at the time. Thanks for the help.
madhan ravi
madhan ravi le 13 Déc 2018
No problem , anytime :)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by