필터 지우기
필터 지우기

Fill new row of cell array after delimiter

조회 수: 2 (최근 30일)
Priya
Priya 2013년 4월 17일
My cell array (1 X 11) is as follows:
a = {'A','B','C',';','D','E','F',';','1','2','3'}
Each character
I want a matlab program to recognize ';'(semicolon) as delimiter and whatever follows it comes to next row.
Desired output is a cell array of order 3 X 3
{ 'A','B','C'
'D','E','F'
'1','2','3' }

채택된 답변

Jan
Jan 2013년 4월 17일
a = {'A','B','C',';','D','E','F',';','1','2','3'};
sep = find(strcmp(a, ';'));
b = a;
b(sep) = [];
b = transpose(reshape(b, sep(1) - 1), []);
  댓글 수: 2
Priya
Priya 2013년 4월 17일
Hi Jan
It worked perfectly..
b = transpose(reshape(b, sep(1) - 1), [ ]);
But I did not understand the last line syntax. What does [ ] denotes ?
Jan
Jan 2013년 4월 17일
It is a typo. The parenthesis must move:
b = transpose(reshape(b, sep(1) - 1, []));
Then RESHAPE changes the shape such, that the result has sep(1)-1 rows and the number of columns is determined automatically by the number of elements.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by