How to import excel data to simin block as input and export output to excel through simout block?
7 次查看(过去 30 天)
显示 更早的评论
How to import excel data to simin block as input and export output to excel through simout block? in=xlsread(filename,c,'temp','b2') out=xlswrite('temp.xls'), is it correct??
0 个评论
回答(1 个)
Shubham
2024-8-21
Hi venkatatejeshreddy,
To import excel data to “from workspace" block (simin) and export output to excel through "to workspace" block (simout), you can use the help of model "Callbacks" which can be accessed from Modelling Tab -> "Model Properties".
For importing excel data to "from workspace" block, you can use the model's "PreLoadFcn". Here's is an example pre-load function that can be used to import excel data to "from workspace" block:
% Read data from the Excel file
filename = 'random_data.xlsx';
data = readmatrix(filename, 'Sheet', 'Sheet1');
% Extract time and signal
time = data(:, 1);
signal = data(:, 2);
% Prepare data for the Simin block
simin = [time, signal];
% Assign to base workspace
assignin('base', 'siminData', siminData);
For exporting excel data from "to workspace" block, you can use model's "StopFcn". Here's is an example of simulation stop function that can be used to export data to excel sheet:
% Retrieve the simulation output from the workspace
outputData = evalin('base', 'simout');
% Define the filename for the Excel file
outputFilename = 'simulation_output.xlsx';
% Since the output is an array, assume the first column is time
outputMatrix = outputData;
% Write the simulation output to the Excel file
writematrix(outputMatrix, outputFilename, 'Sheet', 'Sheet1', 'WriteMode', 'overwrite');
% Inform the user
disp(['Simulation output written to ', outputFilename]);
Please note that you need to configure your "Save format" according to your requirements from "Block Parameters" of "To Workspace" block.
Hope this helps.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!