assigning values with []
显示 更早的评论
[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 个评论
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
2025-4-14
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!