필터 지우기
필터 지우기

Ignore rows in cell with no delimiters

조회 수: 10 (최근 30일)
satwick guturu
satwick guturu 2022년 10월 22일
답변: Jan 2022년 10월 22일
I have a cell array A =
{ a1 = 1}
{ a2 = 2}
{ a3 = 3}
{ a4}
{ a5}
{ a6 = 6}
I have used a split command to split the cell A into two cells based on the delimiter ( B = split(A ,'='); )
I get an error
Element 4 of the text contains 0 delimiters while the previous elements have 1. All elements must contain the same number of delimiters.
I want the output to be
B =
{a1} {1}
{a2} {2}
{a3} {3}
{a4}
{a5}
{a6} {6}
Can anyone help me in this ?
  댓글 수: 2
Image Analyst
Image Analyst 2022년 10월 22일
That's not MATLAB code. See:
A =
Invalid expression. Check for missing or extra characters.
{ a1 = 1}
{ a2 = 2}
{ a3 = 3}
{ a4}
{ a5}
{ a6 = 6}
Please either give code to generate A properly or attach A in a .mat file. I also have no idea what you mean for B so create a B and attach it in the .mat file also so we can see what it really is.
satwick guturu
satwick guturu 2022년 10월 22일
Sorry for my vague explanation above. Below would be the code
A = {'a1 = 1'; 'a2 = 2'; 'a3 = 3'; 'a4 ';'a5 ';'a6 = 6';'a7 = 7'};
B = split(A,'=');
and the error
Error using split (line 99)
Element 4 of the text contains 0 delimiters while the previous elements have 1. All elements must contain the same number of delimiters.

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

답변 (1개)

Jan
Jan 2022년 10월 22일
You want the output:
B =
{a1} {1}
{a2} {2}
{a3} {3}
{a4}
{a5}
{a6} {6}
This is not possible. A cell matrix is still a matrix and this means, that all rows must have the same number of elements. This is the cause for the split function to fail.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by