convert cell to a list

조회 수: 20 (최근 30일)
Izem
Izem 2020년 9월 22일
댓글: Izem 2020년 9월 22일
Let's say I have 2 cells X = {'1 2 3 4 5 6'} and Y = {'7 8 9 10 11 12'}. I want to plot(X,Y), is there a way to do it directly ? Else, how can I convert X and Y to lists ?
Thanks in advance,

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 9월 22일
You can use str2num to convert the char array to numeric values
X = {'1 2 3 4 5 6'};
Y = {'7 8 9 10 11 12'};
plot(str2num(X{1}), str2num(Y{1}))
  댓글 수: 5
Ameer Hamza
Ameer Hamza 2020년 9월 22일
str2double() only work if you only have a single number, such as, X = {'1'}. In your case, str2num() will be used. You can suppress the warning by typing the comment after the line.
plot(str2num(X{1}), str2num(Y{1})) %#ok<ST2NM>
Izem
Izem 2020년 9월 22일
Alright! thanks again.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by