필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by