How to separate a cell array based on existing strings?

1 次查看(过去 30 天)
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]

采纳的回答

Akira Agata
Akira Agata 2017-7-15
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 个评论
khadija portu
khadija portu 2019-7-10
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by