Select elements in a cell array

20 ビュー (過去 30 日間)
Daniele Testori
Daniele Testori 2015 年 11 月 3 日
コメント済み: Daniele Testori 2015 年 11 月 3 日
Hi, I have a cell array that is sized 1x31 and each element is Nx7, N changes in every cell. I have an array with the maximum of the 4th column of each cell, now I want to extract in a new cell array (always 1X31) all the rows and colums of each cell which elements of the fourth column of the cell (i) are the same of max (i) For example:
% A is the vector of the maximun elements
A=[2 3 4];
% B is my cell array of 3 cells
B=[1 2 3 [7 3 4 [1 4 5
4 5 6 3 2 1] 2 4 6
1 2 3] 3 4 7]
%I would like my result C would be a cell array that selects the elements of the matrix which second column is igual to corresponding maximum
C=[1 2 3 [7 3 4] [1 4 5
1 2 3] 2 4 6
3 4 7]
Thank everyone for helping

採用された回答

Stephen23
Stephen23 2015 年 11 月 3 日
編集済み: Stephen23 2015 年 11 月 3 日
A = [2,3,4];
B = {[1,2,3;4,5,6;1,2,3], [7,3,4;3,2,1], [1,4,5;2,4,6;3,4,7]};
C = {};
for k = numel(B):-1:1
C{k} = B{k}(A(k)==B{k}(:,2),:);
end
creates this output cell array C:
>> C{:}
ans =
1 2 3
1 2 3
ans =
7 3 4
ans =
1 4 5
2 4 6
3 4 7
  1 件のコメント
Daniele Testori
Daniele Testori 2015 年 11 月 3 日
I 've tried and it works, thank u so much ;)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by