I have a cell array (36*72*1000), I wish to extract every other cell column-wise and every cell row-wise...

5 vues (au cours des 30 derniers jours)
So,
I want to extract cell a2, b4, c6 etc from:
a1 a2 a3 a4;
b1 b2 b3 b4;
ie. I should have 36 values, which I would like displayed as a column for each of my 1000 matrices. So a new cell array 36*1*1000 - does this make sense?!
Can someone please show me how this can be done?
Thanks in advance...

Réponse acceptée

Sean de Wolski
Sean de Wolski le 17 Août 2012
Modifié(e) : Sean de Wolski le 17 Août 2012
C(:,2:2:end,:) %all rows, even columns, all pages
More
Since you only want one element from each row, it will require a little extra work. Here is one approach:
C = num2cell(rand(4,8,5)); %sample cell
sz = size(C); %how big?
C2 = C(:,2:2:end,:); %remove every other column
idxEye = repmat(logical(eye(sz(1))),[1 1 sz(3)]); %create a logical 3d index of the diagonal
C3 = reshape(C2(idxEye),sz(1),1,sz(3)) %extract and reshape
  3 commentaires
Sean de Wolski
Sean de Wolski le 17 Août 2012
You don't need a for-loop.
C2 = what_I_have_above;
will do the extraction for you!
Sean de Wolski
Sean de Wolski le 17 Août 2012
Actually that will only do the first part - see more.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by