Delete a cell by a criterion???

4 ビュー (過去 30 日間)
Thor
Thor 2013 年 2 月 5 日
Dear all,
I have a cell array of 31x12x9 and in every cell is a 288x3 structure. I want to delete every cell wich has not the 288x3 structure. So all have x3 but the value 288 is in some cells different and these should be deleted! Thank you in advance!

採用された回答

Conrad
Conrad 2013 年 2 月 5 日
Hi Thor, try the following:
% Create dummy data.
S = cell(1,2,2);
l1(288,3).Value = 1; l2(280,3).Value = 1;
S{1,1,1} = l1; S{1,1,2} = l2; S{1,2,1} = l1; S{1,2,2} = l1;
K = S(cell2mat(cellfun(@(x) size(x,1), S, 'UniformOutput', false))==288);
Conrad

その他の回答 (2 件)

Youssef  Khmou
Youssef Khmou 2013 年 2 月 5 日
Your cell array is A of size m=31, n=12 , p=9 :
for x=1:m
for y=1:n
for z=1:p
if(size(A{x,y,z},1)~=288 && size(A{x,y,z},2)~=3)
A{x,y,z}=[];
end
end
end
end

Jan
Jan 2013 年 2 月 5 日
編集済み: Jan 2013 年 2 月 5 日
If C is your data cell:
C(cellfun('size', C, 1) ~= 288) = {[]};
Here the contents of the not matching cell elements are deleted, but not the cells itself. If you want to delete the cells, the result cannot be a cell array anymore but a cell vector only:
C = C(cellfun('size', C, 1) == 288);

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by