How to extract the values that I want in a cell array?
2 ビュー (過去 30 日間)
古いコメントを表示
Hey all,
If we have: a={'1,17951,1,0' ; '1,20345,1,0' ; '1,22950,1,0' ; '1,25360,1,0'};
and I want to exclude 1,...,1,0 which are the same in all and as a result have cell array b as b = {17951 ; 20345 ; 22950 ; 25360}; how can I do that?
Thank you so much for your hint in advance.
Mehdi :)
0 件のコメント
採用された回答
その他の回答 (2 件)
Wayne King
2011 年 11 月 11 日
How is this different than the answer I gave before?
a={1,17951,1,0 ; 1,20345,1,0 ; 1,22950,1,0 ; 1,25360,1,0};
b = cellfun(@(x) x(x>1),a,'uni',0);
b(cellfun(@isempty,b))=[];
2 件のコメント
Fangjun Jiang
2011 年 11 月 11 日
I would use the comma as a way to split them and the select the second column.
a={'1,17951,1,0' ; '1,20345,1,0' ; '1,22950,1,0' ; '1,25360,1,0'};
b=regexp(a,',','split');
c=cellfun(@(x) x{1,2},b,'uni',false);
d=str2double(c)
1 件のコメント
Andrei Bobrov
2011 年 11 月 11 日
Hi Fangjun! Variant:
b = regexp(a,',','split');
b = sortrows(cat(1,b{:})')'
b = b(:,end)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!