seperate elements in cell array
1 回表示 (過去 30 日間)
古いコメントを表示
Hi everybody I have a massive cell array in the form of:
'GLD|41|R|10|05:28:06:361|01/08/2011|f98=158.6'
'GLD|41|T|10|05:28:06:361|01/08/2011|f2=158.3659'
'SLV|41|R|10|05:28:18:901|01/08/2011|f98=39.1628'
'SLV|41|T|10|05:28:18:901|01/08/2011|f2=38.8504'
'GLD|41|R|10|05:28:21:755|01/08/2011|f98=158.6'
'GLD|41|T|10|05:28:21:755|01/08/2011|f2=158.3659'
'SLV|41|R|10|05:28:34:285|01/08/2011|f98=39.1628'
It is always SLV or GLD.
How can I separate this cell array into two cell arrays where one is for all the SLV entries and one is for the GLD entries?
Thanks
0 件のコメント
採用された回答
Wayne King
2012 年 4 月 5 日
I'm assuming each string above is one element of the cell array. To find the SLV and put them in a cell array.
X = {'GLD|41|R|10|05:28:06:361|01/08/2011|f98=158.6',...
'GLD|41|T|10|05:28:06:361|01/08/2011|f2=158.3659',...
'SLV|41|R|10|05:28:18:901|01/08/2011|f98=39.1628',...
'SLV|41|T|10|05:28:18:901|01/08/2011|f2=38.8504',...
'GLD|41|R|10|05:28:21:755|01/08/2011|f98=158.6',...
'GLD|41|T|10|05:28:21:755|01/08/2011|f2=158.3659',...
'SLV|41|R|10|05:28:34:285|01/08/2011|f98=39.1628'};
Y = cellfun(@(x)x(1:3),X,'UniformOutput',false);
Y1 = strcmp(Y,'SLV');
X1 = X(Y1>0);
Then X1 contains only the 'SLV' entries. You can do the same for 'GLD'.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!