Reputation: 9444
Hi I need to store rows of variable length in Matlab.. Can someone point me to the right direction?
Upvotes: 1
Views: 1912
Reputation: 12693
I realized the link in my comment wasn't necessarily clear enough for this kind of question, so I thought I'd expand it to an answer with an example.
Using a cell array, you can hold any data type in each cell. Less generally, this means it works for holding vectors of different lengths, which is what you're asking for.
A = [0 1 2];
B = [3 4];
#% assigning a variable into a cell array:
C{1} = A; #% note the curly braces {} instead of ()
C{2} = B;
#% getting a value out of a cell array:
D = C{2}; #% D is a 1x2 matrix of doubles
E = C(2); #% E is a 1x1 cell
As you can see, to access the elements of a cell array, use curly brackets {}
instead of the usual parentheses ()
, both for reading from/writing to the cell array.
Upvotes: 4