assigning values with []
Ältere Kommentare anzeigen
[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 Kommentare
Image Analyst
am 13 Apr. 2025
Bearbeitet: Image Analyst
am 13 Apr. 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
am 14 Apr. 2025
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!