how can i assign elements of a numeric matrix to variable matrix

30 views (last 30 days)
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
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?
bizzybee in
bizzybee in on 29 Aug 2015
thanks for comment,actually i want to define all this variable in single line. h=1; s=2; d=5; f=6; g=3;

Sign in to comment.

Accepted Answer

Star Strider
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
bizzybee in
bizzybee in on 29 Aug 2015
thanks for answer, it works. in more general form how can i minimize bellow lines in one line,
a=1; s=2; d=5; f=6; g=3;
Star Strider
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);

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!