how can i assign elements of a numeric matrix to variable matrix
30 views (last 30 days)
Show older comments
bizzybee in
on 27 Aug 2015
Commented: Star Strider
on 29 Aug 2015
let i have a matrix a=[2,3,4,4,5] and i have to store it in a variable matrix s=[z,x,c,v,b] such that z=2,x=3,c=4 and so on..
2 Comments
James Tursa
on 27 Aug 2015
Can you be more explicit in your question? From what you have written, I would have just suggested:
s = a;
But I suspect that this isn't what you are asking. Are you trying to deal the elements of "a" into separate variables?
Accepted Answer
Star Strider
on 27 Aug 2015
The most efficient would seem to me to be s=a, but if you want to define the variables in the interim, this works (in the most recent MATLAB releases):
a=[2,3,4,4,5];
ac = mat2cell(a, 1, ones(1,5));
[z,x,c,v,b] = ac{:};
s=[z,x,c,v,b];
2 Comments
Star Strider
on 29 Aug 2015
My pleasure.
Use the deal function. However you have to enter the values manually:
[a,s,d,f,g] = deal(1,2,5,6,3);
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!