putting some matrix in a cell arrays

1 Ansicht (letzte 30 Tage)
mohammad
mohammad am 24 Sep. 2011
There are some Matrix, it's needed putting each of them in an array of a cell that the name of that array be equaled with the name of related matrix.
for example:
a=[1 2 3 4 5 3 2]; b=[4 3 5 67 8 8 7]; c=[3 3 2 4 65 7 8 89];
CELL{1,1}=a; CELL{1,2}=b; CELL{1,3}=c;
Now Question is: how could also be put names of above matrix in CELL?

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 24 Sep. 2011
If you want to have the names, maybe it's better to use structure.
Str.a=a;
Str.b=b;
Str.c=c;
Then you can use Names=fieldnames(Str) to get all the names.
  3 Kommentare
Walter Roberson
Walter Roberson am 24 Sep. 2011
Str(i).value = ... %the data itself
Str(i).name = d(i).name;
mohammad
mohammad am 24 Sep. 2011
So nice, works perfect

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 24 Sep. 2011
In theory the below should work:
var2name = @(varargin) arrayfun(@inputname, 1:nargin, 'Uniform',0);
Then
CELL = var2name(a,b,c);
  13 Kommentare
Fangjun Jiang
Fangjun Jiang am 25 Sep. 2011
Agree! That's a good programming practice. +1
mohammad
mohammad am 26 Sep. 2011
So thanks Walter and Fangjun

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by