Data must be numeric, datetime, duration or an array convertible to double.

1 次查看(过去 30 天)
hello!
I have been asked to plot a graph of voltage against time in which the number of arguments are about 3460. Also the spreadsheet (.xlsx) has 8 columns, which I think may be creating problems. Given below is the code for the same.
T1 = readtable('D:\WARSAW UNIVERSITY OF TECHNOLOGY\SEMESTER 2\Sensors and Mesurement Systems (SMS)\turnX.xlsx','PreserveVariableNames',true);
TT1 = table2timetable(T1,'RowTimes',TimeX);
TimeX = (seconds(0.0):seconds(0.005):seconds(17.295));
x = TimeX
y = TT1;
plot(x,y)

回答(1 个)

dpb
dpb 2019-12-8
编辑:dpb 2019-12-9
TimeX isn't defined in the above code snippet before or by reading the table so that's an inconsistency that should be dealt with in specific code.
The error is from the line
x = TimeX
you can't (directly) turn a duration object/series into a double() array and, furthermore, in this case you don't need (nor want) to. As the error message goes on to say "To convert from durations to numeric, use the SECONDS, MINUTES, HOURS, DAYS, or YEARS functions." so there is a way if one really needs to do so, but that isn't the case here.
Use the timetable variable dot addressing; unfortunately, we don't know what the variable names are in the spreadsheet (or if there was a header row, even) so don't know what they are in the timetable.
The general syntax is:
plot(TT1.Time,TT1.Var1)
ADDENDUM:
Or, if you want to plot more of the variables, you can use the array indexing syntax for the dependent variables.

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by