How to substitute multiple values to the same size variables
显示 更早的评论
I want to shorten multiple substitute equations shown below:
a = 1;
b = 2;
c = 3;
I have tried following expression but it did not work.
[a b c] = [1 2 3];
This may be because MATLAB recognize [ 1 2 3 ] as a single vector.
Does anyone know a proper way to shorten these multiply substitution ?
Thank you.
P.S. :
Thank you for your answering.
I know that it's better to handle variables with array, but I sometimes need to prioritize readability.
采纳的回答
更多回答(1 个)
KSSV
2017-1-31
You must proceed as follows:
a = [1 2 3] ;
then your a,b,c will be a(1),a(2),a(3) respectively.
Or
a = 1 ; b = 2 ; c = 3 ;
iwant = [a b c]
1 个评论
@Yoshi Ri: The pseudo code "[a b c] = [1 2 3]" looks like the three variables have a common nature. If so, storing them in an array could be the best option:
v = [1, 2, 3]
While Stephen's answer matchs your question more precisely, I assume, that KSSV's answer might be better to solve the underlying problem. +1
类别
在 帮助中心 和 File Exchange 中查找有关 Scope Variables and Generate Names 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!