convert cell to a list

14 次查看(过去 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 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by