separation of similar strings in cell array and store in different variables?

1 回表示 (過去 30 日間)
Haritha
Haritha 2019 年 5 月 6 日
コメント済み: Haritha 2019 年 5 月 6 日
I have a cell array as data 1. I need to separate the rows containing 'aa' and save it in one variable (var1) similarly for 'bb','cc' and 'dd'.
a = {'aa';'bb';'cc';'dd';'aa';'bb';'dd';'cc';'aa'}
b = {'1';'2';'3';'4';'5';'6';'7';'8';'9'}
data1 =[a,b]
My output looks like below
Please help me if anyone knows

採用された回答

Guillaume
Guillaume 2019 年 5 月 6 日
One way:
[~, ~, subs] = unique(data1(:, 1));
var = accumarray(subs, (1:size(data1, 1)).', [], @(rows) {data1(rows, :)})
  2 件のコメント
Jan
Jan 2019 年 5 月 6 日
+1. "var" is a builtin function, so prefer another name.
Haritha
Haritha 2019 年 5 月 6 日
I tried a lot finally i got it from you .Thanks a lot..

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by