Clear Filters
Clear Filters

seperate elements in cell array

3 views (last 30 days)
Mate 2u
Mate 2u on 5 Apr 2012
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

Accepted Answer

Wayne King
Wayne King on 5 Apr 2012
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'.

More Answers (0)

Categories

Find more on Cell Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!