assigning values with []
Afficher commentaires plus anciens
[a,b]=[1,2]
Why doesn't this work? How to rewrite into what is easier and more succinct than a=1; b=2?
Just to respond to all the comments and answers, there's certain occasions where my suggested (wrong) syntax is easier than others, e.g. when parameters are defined in an array in 1 go.
2 commentaires
Image Analyst
le 13 Avr 2025
Modifié(e) : Image Analyst
le 13 Avr 2025
More succint? 11 characters is more succint than 8 characters?
length('[a,b]=[1,2]')
length('a=1;b=2;')
So it's not shorter and easier I think is a matter of opinion.
Also I think your suggestion could be ambiguous. Does [a,b]=[1,2] mean a=1;b=2, OR might someone think it could possibly mean that both a AND b are equal to the vector [1,2], like a=[1,2];b=[1,2]. So I think the a=1;b=2 method is a lot more intuitive - there is no possibility of misunderstanding what that means. It's unambiguous and more succint.
feynman feynman
le 14 Avr 2025
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!