dpb
Posts:
6,680
Registered:
6/7/07
|
|
Re: Array of array
Posted:
Dec 26, 2012 10:02 AM
|
|
On 12/26/2012 4:33 AM, CHINEDU wrote: ...
> dpb, your answer is exactly what I wanted. I actually want to create a 2 > dimensional array whose elements are in turn 3-element arrays i.e. To > create a matrix A with > Row 1 = (1,2,3), (2,3,4), (2,4,5) > Row 2 = (4,5,6), (1,2,2), (0,2,1) etc
If you're going to be using regular arrays (in size), then as Bruno and Nasser note it'll be much simpler (as you're discovering w/ the addressing syntax issues) and Matlab will be far more responsive to use normal arrays instead of cell arrays.
Why the insistence on cell arrays--what's the problem domain/usage? Perhaps a better data structure would present itself if others knew the intent here...
> dpb's answer has answered it exactly but I am still having problem of > accessing the elements. I have understood how to access the one-row type > through dpo's answer but the 2D access is not still clear. I mean, how > can I access elements of 2D array whose elements are subarrays? dpo > please, help. > > I have done something like this A ={[1,2,3],[0,-1,4];[-2,-3,-4],[9,8,7]} > And am accessing the elements using > A{r,c}(i) for the i-th element of the r-th column and c-th column eg. > A{1,2}(2)=-1 > Is this correct?
Yes, to get to a cell content, address the cell in curlies first, then the element(s) in normal parens after.
doc paren
and look for "multi-level addressing" as a subject in the documentation for more details...
--
|
|