Garnett - 2021-09-18T13:50:11+00:00
Question: How do I save Simulink parameters from Base Workspace to Excel file?
I have a list of parameters that my Simulink model uses during simulation. I would like to export the parameters from the base workspace to an Excel sheet with the first column containing the parameter names and the second column containing the parameter values. What is a possible method for accomplishing this?
Expert Answer
Prashant Kumar answered .
2025-11-20
The "who" function can be used to get the current parameter names from the base workspace. The values of these parameters can be determined by evaluating each parameter string name in the base workspace. Finally, a cell array with the parameter names and values can be constructed and saved to an Excel spreadsheet via the "xlswrite" function.
To demonstrate a basic workflow, see the following example:
% Clear all variables to start fresh, for example
clear all; % If other variables are in the workspace, they should be removed
% Generate arbitrary parameters
Kp = 1;
Ki = 0.1;
Kd = 0.01;
% Get all variables in the workspace
varNames = who;
varNames = flipud(varNames); % The "who" function flips the order of parameters, "flipup" returns this order to default
for i = 1:numel(varNames),
cellToSave{i,1} = varNames{i}; % Add parameter names to first column of cell
cellToSave{i,2} = eval(varNames{i}); % Add parameters values to second column of cell
end
% Specify the file name
filename = 'Controller_Parameters.xlsx';
xlswrite(filename,cellToSave);
Not satisfied with the answer ?? ASK NOW