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

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 comentario

"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.

Iniciar sesión para comentar.

Más respuestas (1)

Anteneh Zewdu
Anteneh Zewdu el 6 de Dic. de 2018
I found the answer from a friend
[a, b, c, d] = deal(5)

3 comentarios

madhan ravi
madhan ravi el 6 de Dic. de 2018
Editada: madhan ravi el 6 de Dic. de 2018
Dude that's exactly what I answered , it's not nice to accept your own answer after someone has answered !
Madhan brother, I haven't seen your answer at the time. Thanks for the help.
No problem , anytime :)

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Productos

Versión

R2017b

Preguntada:

el 6 de Dic. de 2018

Comentada:

el 13 de Dic. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by