Accessing cell array entries using arrays
I have a multi-dimensional cell array and matrix, whose columns correspons to indices of the cell array. I want to populate the cells with arrays that correspond to the indices of the columns that refer to the given cell.
Minimal example:
A=cell(2,2);
B=[1 2 2 1 1; 2 1 2 1 2]
A{1,1}=[4];
A{1,2}=[1,5];
A{2,1}=[2];
A{2,2}=[3]
I’m trying to do this automatically by looping over the columns of the matrix B, but I can’t figure out how to extract the entries of the array without keeping the array form. Calling neither
A(B(:,1))
nor
A{B(:,1)}
produces the correct entry
A{1,2}I have a multi-dimensional cell array and matrix, whose columns correspons to indices of the cell array. I want to populate the cells with arrays that correspond to the indices of the columns that refer to the given cell.
Minimal example:
A=cell(2,2);
B=[1 2 2 1 1; 2 1 2 1 2]
A{1,1}=[4];
A{1,2}=[1,5];
A{2,1}=[2];
A{2,2}=[3]
I’m trying to do this automatically by looping over the columns of the matrix B, but I can’t figure out how to extract the entries of the array without keeping the array form. Calling neither
A(B(:,1))
nor
A{B(:,1)}
produces the correct entry
A{1,2} I have a multi-dimensional cell array and matrix, whose columns correspons to indices of the cell array. I want to populate the cells with arrays that correspond to the indices of the columns that refer to the given cell.
Minimal example:
A=cell(2,2);
B=[1 2 2 1 1; 2 1 2 1 2]
A{1,1}=[4];
A{1,2}=[1,5];
A{2,1}=[2];
A{2,2}=[3]
I’m trying to do this automatically by looping over the columns of the matrix B, but I can’t figure out how to extract the entries of the array without keeping the array form. Calling neither
A(B(:,1))
nor
A{B(:,1)}
produces the correct entry
A{1,2} cell array, index, array MATLAB Answers — New Questions