Error scatter plot time vs wind speed (data from a table)

2 vues (au cours des 30 derniers jours)
Marissa Menzel
Marissa Menzel le 31 Mai 2018
Modifié(e) : Greg le 1 Juin 2018
I am trying to make a simple scatter plot with time on the x-axis and wind speed on the y-axis. I loaded in my data from a txt file as a table and then tried to use table2array to plot since it needs numeric values not table data. I also tried using double and got another error.
Error Message: Error using scatter (line 55) Input arguments must be numeric or objects which can be converted to double.
Error in windconversions (line 18) scatter(time,wnd_TS)
T = readtable('allunderway.txt', 'HeaderLines', 2);
%A = table2array(T)
date = T(:,1);
time = T(:,2);
wnd_TD = T(:,10);
wnd_TS = T(:,11);
table2array(wnd_TS);
table2array(time);
%double(wnd_TS);
scatter(time,wnd_TS)
  2 commentaires
Paolo
Paolo le 31 Mai 2018
Could you attach the .txt file to your question?
Marissa Menzel
Marissa Menzel le 31 Mai 2018
Done!

Connectez-vous pour commenter.

Réponses (1)

Greg
Greg le 1 Juin 2018
Modifié(e) : Greg le 1 Juin 2018
You're misunderstanding how MATLAB operates. Functions like table2array don't manipulate the variable in place, they return it as an explicit output variable. Replace
table2array(wnd_TS);
table2array(time);
with
wnd_TS = table2array(wnd_TS);
time = table2array(time);
Better than that though is to index into tables properly:
scatter(T.Time_GMT,T.Wnd_TS);
  2 commentaires
Marissa Menzel
Marissa Menzel le 1 Juin 2018
I tried the new scatter line and got an error Error using windconversions (line 20) Unrecognized variable name 'time'.
Greg
Greg le 1 Juin 2018
Sorry, I was looking at your time = T(:,2) line rather than the data file. See updated answer.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by