plotting a column of a timetable

10 views (last 30 days)
Matthias Ley
Matthias Ley on 7 Jan 2019
Answered: Peter Perkins on 23 Jan 2019
Hi,
Im trying to plot a column of a timetable which looks like this:
I wanna plot one column of the table over the time for the whole length of the table. I tried using this:
plot(phaseOne.VideoTime, phaseOne.Happy);
phaseOne is the timetable, VideoTime the old columns name with the time and Happy one of the columns i want to plot.
The error im getting is this:
Error using plot
Invalid data argument.
Error in work (line 33)
plot(phaseOne.VideoTime, phaseOne.Happy);
What i noticed are the single quotation marks around my data, which were not included in my original data.
Is the type of the array a problem? Do i need to convert the columns into numbers or similar to plot? I assume i also would have to convert the time/duration back into real numbers then.
Best regards,
Matthias

Accepted Answer

Stephan
Stephan on 7 Jan 2019
Edited: Stephan on 7 Jan 2019
Hi,
the quotes tell you, that Matlab does not interpret this values as numbers but as datatype char.
You can check data type for every column by clicking the little arrow which appears if you move the mouse to the column name (here field b) in the "variables" tab:
Try to convert them to numbers:
phaseOne.Happy = str2num(phaseOne.Happy)
After performing this operations on the needed columns, the plot command should work properly.
Best regards
Stephan
  3 Comments
Stephan
Stephan on 7 Jan 2019
there is no loss of Information - type:
format long
phaseOne.Happy
numeric values are displayed with 4 digits by standard. internally the numbers are stored correct .
Matthias Ley
Matthias Ley on 7 Jan 2019
Ah, thats a relieve. Thank you Stephan, you helped alot ! :)

Sign in to comment.

More Answers (1)

Peter Perkins
Peter Perkins on 23 Jan 2019
Matthias, it seems like you've solved your immediate issue. But still, you really ought to figure out how those numeric data became text, and fix the problem at its source. It may be that you need to use detectimportoptions when using readtable, for example.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!