
Why do I get a "Invalid variable" error when a time table for simulation input has more than one variable?
4 views (last 30 days)
Show older comments
MathWorks Support Team
on 30 May 2022
Answered: MathWorks Support Team
on 30 May 2022
Why can't I use a timetable with multiple variables for simulation input? I am receiving the following error:
Invalid variable '<variable_name>' specified as input in '<model_name>'. Timetable for simulation input cannot have more than one variable.
Accepted Answer
MathWorks Support Team
on 30 May 2022
This is intended behavior as of MATLAB R2022a. A timetable object can have only one variable when used for simulation input.
Consider one of the following possible workarounds:
(1) Split up the multi-variable timetable into several one-variable timetables and assign each one to a data inport, as a leaf signal for a bus-valued inport, or to a separate "From Workspace" block.
% Time in seconds
time = linspace(0,10,100)';
v1 = rand(size(time));
v2 = rand(size(time));
% Create two separate one-variable timetable objects to assign to
% separate inports or From Workspace blocks
TT1 = timetable(seconds(time),v1);
TT2 = timetable(seconds(time),v2);
.
(2) Use a timeseries object instead of a timetable object. The code below creates a timeseries object containing two variables (columns) – 'v1' and 'v2':
% Time in seconds
time = linspace(0,10,100)';
v1 = rand(size(time));
v2 = rand(size(time));
% Create a timeseries object named t, containing the time in seconds, and
% v1 and v2 variables
t = timeseries([v1,v2],time,'Name','t');
The timeseries object 't' can then be loaded in Simulink with the "From Workspace" block. Individual variables (columns) can be accessed with a "Demux" block. Refer to the image below:

(3) In case your data is originally stored in a spreadsheet, note that there is a "From Spreadsheet" block that supports multiple variables as outputs:
0 Comments
More Answers (0)
See Also
Categories
Find more on Sources in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!