Manipulate Cell Arrays

조회 수: 1 (최근 30일)
fcarl
fcarl 2011년 8월 29일
Hi,
I have a problem regarding cell arrays:
I have an cell array named sets of 10 cells. In each cell I want to store arrays with 2 columns and a variable numer of rows. I don`t know how to add a new row into a special cell. I think it is an indexing problem?
sets=cell(1,10);
sets{1,1}=[sets(1,1) [3,3]];
What is wrong with that? So the problem is: how to concatenate a matrix stored in a cell array cell with a new row?
Thanks for your efforts!

채택된 답변

fcarl
fcarl 2011년 8월 29일
Okay. Problem was solved! it has to be:
sets{1,1}=[sets{1,1} [3,3]];

추가 답변 (1개)

Lucas García
Lucas García 2011년 8월 29일
Let's see if I understand your question. First, you say: " In each cell I want to store arrays with 2 columns and a variable numer of rows".
This array can't be a matrix, since matrices must have all the same number of rows. But each column can be placed in a cell:
x = (1:10)';
y = (1:11)';
sets{1,1} = {x,y};
By using the braces, {x,y} , you are creating a cell of size 1x2 in the first position of the cell sets. If you want now to index into the cell sets and add a row no.12 with value 12 in the position where you placed y, you can do the following:
sets{1,1}{1,2}(12,1) = 12;
This is what you now have in the position 1,1 of cell sets:
>> sets{1,1}
ans =
[10x1 double] [12x1 double]
And this is what you have in second cell contained in the first cell of cell sets:
>> sets{1,1}{1,2}
ans =
1
2
3
4
5
6
7
8
9
10
11
12

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by