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?

 채택된 답변

MathWorks Support Team
MathWorks Support Team 2025년 4월 28일
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.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

제품

릴리스

R2021a

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by