How do I use a From Workspace block with table data?

I have an Excel file that contains timestamps in the first column and different measurements in the other columns:
Because it contains date timestamps, the file is not compatible with the "From Spreadsheet" block:
Error encountered in block mdl/From Spreadsheet Caused by: First column (time column) must contain numeric values.
After importing the file into my MATLAB base workspace with "readtimetable", and trying to use this variable with a "From Workspace" block, I get:
Invalid variable 'TT' specified as input in 'mdl/From Workspace'. Time must be a Duration vector.
How can I use my spreadsheet as Simulink simulation input?

 Respuesta aceptada

The "From Workspace" block will only accept time as a duration vector, which is documented here:
You can import the Excel data using our Import Tool as 'table' type and then convert the 'table' to a 'timetable':
TT = table2timetable(mySpreadsheet);
Alternatively, you can also directly import the Excel data into a timetable:
TT = readtimetable('mySpreadsheet.xlsx');
Then, convert the timestamps in your timetable into a duration vector by deducting the timestamps from the start time:
TT.Properties.RowTimes = TT.Properties.RowTimes - TT.Properties.StartTime;
Next, you will see this error when you try to run your Simulink model:
Invalid variable 'TT' specified as input in 'mdl/From Workspace'. Timetable for simulation input cannot have more than one variable.
When you load data using a timetable, the timetable must contain data for a single signal, in only one column.
You can create 3 separate timetable variables:
TT1 = removevars(TT,[2 3]);
​​​​​​​TT2 = removevars(TT,[1 3]);
TT3 = removevars(TT,[1 2]);
And add one From Workspace block for each variable TT1, TT2, TT3.
Alternatively, convert the timetable to a timeseries:
ts = timeseries([TT.Var1,TT.Var2,TT.Var3],seconds(TT.Time));
However, note that timeseries are no longer recommended.

Más respuestas (0)

Categorías

Más información sobre Data Import from MATLAB en Centro de ayuda y File Exchange.

Productos

Versión

R2021a

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by