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

29 Ansichten (letzte 30 Tage)
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 Kommentare
James Tursa
James Tursa am 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 am 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;

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 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 Kommentare
bizzybee in
bizzybee in am 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 am 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);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by