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,

 Réponse acceptée

Ameer Hamza
Ameer Hamza le 22 Sep 2020

1 vote

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 commentaires

Izem
Izem le 22 Sep 2020
Thank you!
Ameer Hamza
Ameer Hamza le 22 Sep 2020
I am glad to be of help!
Izem
Izem le 22 Sep 2020
That's kind. What's the difference between str2num and str2double ? (cuz matlab suggested to use str2double instead od str2num)
Ameer Hamza
Ameer Hamza le 22 Sep 2020
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 le 22 Sep 2020
Alright! thanks again.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by