How do I display simulink simulation data as a table
51 次查看(过去 30 天)
显示 更早的评论
I would like to generate a simple table with the data from a Simulink simulation. Basically just a table with column labels in the top row, time in the first column and the data from logged values in each column. How do I generate this table?
I just want my model to put out something I can read from in Matlab easily to generate other tables. I have been using the export function in the simulink data inspector to get the data to excel, but I would like to move to dealing with the tables in Matlab as I have to run a bunch of simulations simultaneously and compile the data from multiple simulations into tables.
I am struggling finding ways to reference the data from simulink output in codes to write scripts to generate the tables that I want and at this point can't seem to reference the output data.
0 个评论
采纳的回答
Ayush Modi
2024-4-12
Hi Dieter,
I understand you want to get the output of simulink model in the MATLAB workspace, so that you can create a table from that data.
Please refer to the following MathWorks documentation for information on how to save or log the simulation data to the workspace:
Once you have the data in the workspace, here is how you can create a table with the specified requirement:
% Assuming your data is logged to a variable named 'logsout'
% and you want to create a table with time and these signals
% tout is the time output from the simulation data
% Initialize a table with the time column
T = table(tout, 'VariableNames', {'Time'});
% Loop through each element in the dataset to add it to the table
for i = 1:logsout.numElements
% Get the signal name
signalName = logsout.getElement(i).Name;
% Get the signal data
signalData = logsout.getElement(i).Values.Data;
% Add the data as a new column in the table
T.(signalName) = signalData;
end
% Now, T is a table with time and all your logged signals
Hope this helps!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sources 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!