How to separate a cell array based on existing strings?

1 Ansicht (letzte 30 Tage)
Calabrese
Calabrese am 15 Jul. 2017
Kommentiert: khadija portu am 10 Jul. 2019
I have a cell array that is 2452x5 but it has been reduced for the purpose of this question. I would like to separate the cell array, raw, into separate matrices based on a string within rows ('VR26'). The string isn't always present in the first column, the cell array below was simplified.
raw =
'VR26' [ 0.0539]
'VR26' [ 0.0015]
'VR26' [ 14.0853]
'VR27' [ 0.0658]
'VR27' [ 0.0022]
'VR27' [ 25.7290]
'VR40' [ 0.1425]
'VR40' [ 0.0566]
'VR40' [ 1.7189]
'VR40' [ 1.3351]
'VR40' [ 6.0185e-04]
'VR40' [ 0.0085]
'VR40' [ 8.6243]
Be split into...
VR26 =
'VR26' [ 0.0539]
'VR26' [ 0.0015]
'VR26' [ 14.0853]
raw2 =
'VR27' [ 0.0658]
'VR27' [ 0.0022]
'VR27' [ 25.7290]
'VR40' [ 0.1425]
'VR40' [ 0.0566]
'VR40' [ 1.7189]
'VR40' [ 1.3351]
'VR40' [6.0185e-04]
'VR40' [ 0.0085]
'VR40' [ 8.6243]

Akzeptierte Antwort

Akira Agata
Akira Agata am 15 Jul. 2017
You can do this by using cellfun function, like:
% Sample cell array
C = [{'VR26';'VR26';'VR27';'VR40'},num2cell(rand(4,1))];
idx = cellfun(@(x) strcmp(x, 'VR26'), C(:,1));
% Extracted data (VR26)
C1 = C(idx,:);
% Others
C2 = C(~idx,:);
  1 Kommentar
khadija portu
khadija portu am 10 Jul. 2019
thank you for this code
i want to separate a matrix with binary code with 10 rows into 2 matrix five each, what should i add bcz after running that i had like each column itsef could you tell me what should i do

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by