3
votes

C is a cell consisting of some vectors:

C = {[1, 2], [2, 3]};

I want to read the first entry of the first vector in C. But I can not use the following:

C{1}[2]

I get the following error:

Error: Unbalanced or unexpected parenthesis or bracket.

How can I make it read the value?

1
matlab uses () to access elements of vectors, not [].ThijsW

1 Answers

6
votes

You can access individual elements of matrices in cell array like this:

C{n,m}(ii,jj);

This will give you element (ii,jj) of the matrix at index (n,m) of the cell array.

Hence, for your particular example,

val = C{1,1}(1,1) (or val = C{1}(1))

will assign the value of the first element of the first vector in the cell array to the variable val.