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!
|
|
0
|
|
|
|
Reply
|
silvertonm (53)
|
6/4/2010 3:28:03 PM |
|
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) .';
|
|
0
|
|
|
|
Reply
|
Walter
|
6/4/2010 3:43:30 PM
|
|
On Jun 4, 8:43=A0am, Walter Roberson <rober...@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. =A0=
I
> > would like to use the index_matrix to find the corresponding values in
> > the cell. =A0That 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 =3D1:length(index_matrix)
> > for ii=3D1:size(cell_data,2)
> > new(i,ii)=3Dcell_data{i,ii}(index_matrix(i));
> > end
> > end
>
> If I understand correctly,
>
> new =3D 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 =3D=3D> @(C)C{index_matrix}
index_matrix is a matrix not a cell of just 10 numbers, would be
similar to something like:
index_matrix =3D [14 20 1 3 55 40 99 1001 5 91];
so that the new variable would be
new =3D [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!
|
|
0
|
|
|
|
Reply
|
ms
|
6/4/2010 4:07:45 PM
|
|
|
2 Replies
479 Views
(page loaded in 0.074 seconds)
|