필터 지우기
필터 지우기

Multi Dimensional Cell Array

조회 수: 73 (최근 30일)
xplore29
xplore29 2013년 5월 1일
Can we create a single multi-dimensional cell array of variable size dimensions.
I have matrices (all of same dimensions) A1,A2,A3,A4 AA1,AA2,AA3,AA4,BB1,BB2,BB3,BB4
I was wondering if whether I can store these matrices like
cellarray{1,1,1}=A1 cellarray{1,2,1}=A2......cellarray{1,4,1}=A4
cellarray{1,1,2}=AA1 cellarray{1,2,2}=AA2......cellarray{1,4,2}=AA4
cellarray{2,1,2}=BB1 cellarray{2,2,2}=BB2......cellarray{2,4,2}=BB4
I understand that cells are good for storing data of variable dimensions but for this problem its the dimensions which are variable instead of data itself
  댓글 수: 1
Jan
Jan 2013년 5월 1일
I do not understand the question. You have posted the code required to create cellarray already. This implies, that the answer is:
Yes, obviously it is possible that you can store the matrices as you have shown.
I assume, you want something more general.

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

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 1일
cellarray={A1,A2,A3,A4,AA1,AA2,AA3,AA4,BB1,BB2,BB3,BB4}
  댓글 수: 2
Jan
Jan 2013년 5월 1일
The question contains the detail, that e.g. BB4 should be found at the index [1,2,1]. Does your answer address this? If not, are there any reasons to omit this?
Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 1일
I think this is the simple way to store those matrices, maybe we have to store also their names:
cellarray_names={'A1','A2',...}.
I do not know exactly what are the OP intentions. I was hoping he comments my answer

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


Babak
Babak 2013년 5월 1일
maxsize1 = 100;
maxsize2 = 100;
maxsize3 = 100;
mycell = cell(maxsize1 ,maxsize2 ,maxsize3 );
mycell{1,1,1} = A1;
mycell{1,2,1} = A2;
mycell{1,4,1} = A4;
mycell{1,1,2} = AA1;
mycell{1,2,2} = AA2;
mycell{1,4,2} = AA4;
mycell{2,1,2} = BB1;
mycell{2,2,2} = BB2;
mycell{2,4,2} = BB4;
// eventually you can chop the unused part of the mycell to the index of the date you have entered. notice that the rest of the cell variables that you haven't entered any data in are empty
mycell = mycell(1:2,1:4,1:2);
  댓글 수: 3
Jan
Jan 2013년 5월 2일
@xplore29: This sound very strange. The dimensions of the multi-dimensional (cell) array are fixed. Otherwise it would not be something you should call "array", because this term means, that the data are arranged regularily.
I assume, a nested array should satisfy your needs:
X = cell(1,2,3);
Y = cell(3,4,5);
C = {X, Y};
Babak
Babak 2013년 5월 2일
@xplore29: cell is the only type of variable in MATLAB that I know of, which can have "empty" elements. Say cell(2,3) you get a 2 by 3 array of empty elements. If you don't need to use those elements it's quite OK. Just keep track of which elements are you filling up so you know you only use those later in your code.
A = cell(2,3);
A{1,1} = 6;
A{1,2} = [ 3 4 5;3 4 5];
A{2,2} = '34';
A{2,3} = 'somename';
A
A(2,1) is an empty cell, element of A. Not filled up and won't be used in future.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by