Extracting neighbouring cells in a cell array
This is a follow up to this question. I have cell array and a list of cells of interests (given as a matrix, whose columns correspond to the indices of cells). I want to access and concatenate the entries of all cells located +/- 1 the cell of interest.
For example, as suggested in the accepted answer to the references question, I construct the cell array A as follows
B = [1,2,2,1,1; 2,1,2,1,2];
V = 1:size(B,2);
A = accumarray(B.’,V(:),[],@(m){m.’})
Now I have the matrix C with the cells of interest
C=[1 2; 1 2]
I have 2 neighbourhoods that I want to explore
NbhInd1=[1 1 2; 1 2 1];
NbhInd2=[1 2 2; 2 2 1];
In the end, I want to be able to get two arrays of neighbourhoods (can be sorted or unsorted)
Nbh1=[4 1 5 2]
Nbh2=[1 5 3 2]
I have 3 problems:
(Same as in the referenced question): I don’t know how to convert an array into a proper index to refer to the correct cell of A. I.e. A{[1,1]} or A ([1,1]) is not the same as A{1,1}, and I need to the latter.
How to automate the construction of indices of the neighbourhoods. In principle, I can use combinations() but it gives too many indices. Also, I’m not sure how to automatically easily convert [1,1] into table2array(combinations(1:2,1:2)), i.e. splitting an array into its coordinates and manipulating separately
The true array A has high dimensionality (e.g. size(A)=repmat(9,[1,10])), so I’d like to minimize the number of loops.This is a follow up to this question. I have cell array and a list of cells of interests (given as a matrix, whose columns correspond to the indices of cells). I want to access and concatenate the entries of all cells located +/- 1 the cell of interest.
For example, as suggested in the accepted answer to the references question, I construct the cell array A as follows
B = [1,2,2,1,1; 2,1,2,1,2];
V = 1:size(B,2);
A = accumarray(B.’,V(:),[],@(m){m.’})
Now I have the matrix C with the cells of interest
C=[1 2; 1 2]
I have 2 neighbourhoods that I want to explore
NbhInd1=[1 1 2; 1 2 1];
NbhInd2=[1 2 2; 2 2 1];
In the end, I want to be able to get two arrays of neighbourhoods (can be sorted or unsorted)
Nbh1=[4 1 5 2]
Nbh2=[1 5 3 2]
I have 3 problems:
(Same as in the referenced question): I don’t know how to convert an array into a proper index to refer to the correct cell of A. I.e. A{[1,1]} or A ([1,1]) is not the same as A{1,1}, and I need to the latter.
How to automate the construction of indices of the neighbourhoods. In principle, I can use combinations() but it gives too many indices. Also, I’m not sure how to automatically easily convert [1,1] into table2array(combinations(1:2,1:2)), i.e. splitting an array into its coordinates and manipulating separately
The true array A has high dimensionality (e.g. size(A)=repmat(9,[1,10])), so I’d like to minimize the number of loops. This is a follow up to this question. I have cell array and a list of cells of interests (given as a matrix, whose columns correspond to the indices of cells). I want to access and concatenate the entries of all cells located +/- 1 the cell of interest.
For example, as suggested in the accepted answer to the references question, I construct the cell array A as follows
B = [1,2,2,1,1; 2,1,2,1,2];
V = 1:size(B,2);
A = accumarray(B.’,V(:),[],@(m){m.’})
Now I have the matrix C with the cells of interest
C=[1 2; 1 2]
I have 2 neighbourhoods that I want to explore
NbhInd1=[1 1 2; 1 2 1];
NbhInd2=[1 2 2; 2 2 1];
In the end, I want to be able to get two arrays of neighbourhoods (can be sorted or unsorted)
Nbh1=[4 1 5 2]
Nbh2=[1 5 3 2]
I have 3 problems:
(Same as in the referenced question): I don’t know how to convert an array into a proper index to refer to the correct cell of A. I.e. A{[1,1]} or A ([1,1]) is not the same as A{1,1}, and I need to the latter.
How to automate the construction of indices of the neighbourhoods. In principle, I can use combinations() but it gives too many indices. Also, I’m not sure how to automatically easily convert [1,1] into table2array(combinations(1:2,1:2)), i.e. splitting an array into its coordinates and manipulating separately
The true array A has high dimensionality (e.g. size(A)=repmat(9,[1,10])), so I’d like to minimize the number of loops. cell array, array, index MATLAB Answers — New Questions