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