putting some matrix in a cell arrays

조회 수: 1 (최근 30일)
mohammad
mohammad 2011년 9월 24일
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?

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 9월 24일
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
Walter Roberson
Walter Roberson 2011년 9월 24일
Str(i).value = ... %the data itself
Str(i).name = d(i).name;
mohammad
mohammad 2011년 9월 24일
So nice, works perfect

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by