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

 採用された回答

Stephan
Stephan 2019 年 1 月 7 日
編集済み: Stephan 2019 年 1 月 7 日

0 投票

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 件のコメント

Matthias Ley
Matthias Ley 2019 年 1 月 7 日
Hey Stephan,
thanks for your quick reply! I had a similar idea, and this works aswell, but:
str2num doesnt work with the following error:
Error using str2num (line 35)
Input must be a character vector or string scalar.
Error in work (line 35)
plot(phaseOne.VideoTime, str2num(phaseOne.Happy));
however, str2double works, but it cuts my data to 4 decimal places and i lose information.
Do you think there is a way i can define the column as a double, int32 so i can later multiply the column with 100 and not lose information? i hope my idea is somewhat understandable.
Best regards, matthias
Stephan
Stephan 2019 年 1 月 7 日
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 2019 年 1 月 7 日
Ah, thats a relieve. Thank you Stephan, you helped alot ! :)

サインインしてコメントする。

その他の回答 (1 件)

Peter Perkins
Peter Perkins 2019 年 1 月 23 日

0 投票

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.

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品

リリース

R2018b

質問済み:

2019 年 1 月 7 日

回答済み:

2019 年 1 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by