Reputation: 980
Matlab is really driving me crazy on this point. I just want to access the inner array of a 2d array.
E.g.:
A = [1,1; 2,2; 3,3]
B = [4,4; 5,5; 6,6]
C = [7,7; 8,8; 9,9]
D = [0,0; 1,2; 3,4]
E = [A,B,C,D]
how do I get e.g. B
out of E
again?
By this I mean in the exact same writing styl like X = [4,4; 5,5; 6,6]
Upvotes: 1
Views: 100
Reputation: 2426
You concatenated A, B, C, D horizontally into a new array E. That is not array of arrays, as the other answer pointed out. Suppose the new array is what you want. If you like to extract original B from E, you will need to know A and B's size, in this case both are 3x2. So You can do following:
X = E(:, 3:4); % 3 is size(A,2)+1, numel(3:4) is size(B,2)
Also I think you did not really mean "writing style", since that is just a way to write assignment.
Upvotes: 2
Reputation: 305
The syntax you use concatenates the array to a new one, it is not an array of arrays. If you want an array of arrays, you could use a cell, E = {A,B,C,D}. Then you can get B back using E{2}.
Cells are general containers, each element can contain whatever you want, it does not have to be the same data type. See What is a cell?
Upvotes: 3