From: ms on
I have an index_matrix of index points and has ten index points, so
the length is 10.

I have a 10x3 cell that contains 10 matrices/column of length 9000. I
would like to use the index_matrix to find the corresponding values in
the cell. That is, each index point corresponds to the same row of
cell matrix. For example, the first value of the index_matrix(1,1),
corresponds to cell {1,1}.

I can think of a way to use a for loop, but I was wondering if there
was an easier way?

for i =1:length(index_matrix)
for ii=1:size(cell_data,2)
new(i,ii)=cell_data{i,ii}(index_matrix(i));
end
end

Thanks!








From: Walter Roberson on
ms wrote:
> I have an index_matrix of index points and has ten index points, so
> the length is 10.
>
> I have a 10x3 cell that contains 10 matrices/column of length 9000. I
> would like to use the index_matrix to find the corresponding values in
> the cell. That is, each index point corresponds to the same row of
> cell matrix. For example, the first value of the index_matrix(1,1),
> corresponds to cell {1,1}.
>
> I can think of a way to use a for loop, but I was wondering if there
> was an easier way?

> for i =1:length(index_matrix)
> for ii=1:size(cell_data,2)
> new(i,ii)=cell_data{i,ii}(index_matrix(i));
> end
> end

If I understand correctly,

new = cellfun(@(C) C{index_matrix}, cell_data) .';
From: ms on
On Jun 4, 8:43 am, Walter Roberson <rober...(a)hushmail.com> wrote:
> ms wrote:
> > I have an index_matrix of index points and has ten index points, so
> > the length is 10.
>
> > I have a 10x3 cell that contains 10 matrices/column of length 9000.  I
> > would like to use the index_matrix to find the corresponding values in
> > the cell.  That is, each index point corresponds to the same row of
> > cell matrix. For example, the first value of the index_matrix(1,1),
> > corresponds to cell {1,1}.
>
> > I can think of a way to use a for loop, but I was wondering if there
> > was an easier way?
> > for i =1:length(index_matrix)
> > for ii=1:size(cell_data,2)
> > new(i,ii)=cell_data{i,ii}(index_matrix(i));
> > end
> > end
>
> If I understand correctly,
>
> new = cellfun(@(C) C{index_matrix}, cell_data) .';- Hide quoted text -
>
> - Show quoted text -

I get an error:

??? Cell contents reference from a non-cell array object.

Error in ==> @(C)C{index_matrix}

index_matrix is a matrix not a cell of just 10 numbers, would be
similar to something like:
index_matrix = [14 20 1 3 55 40 99 1001 5 91];

so that the new variable would be
new = [cell{1,1}(value 14), cell{1,2}(value 14), cell{1,3}(value
14)...;
cell{10,1}(value 91), cell{10,2}(value 91), cell{10,3}
(value 91)];%I hope that makes sense

I tried changing the code to () instead of {} and ended up with a
'new' variable of 5x3 cell full of 5x1 doubles. I would like to end
up with a 5x3 double as the 'new' variable.

Thank you!