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!