@SS,
Yes since you want to load multiple .mat files, it is best to use a MATLAB function block.
Here is a simple example code:
function data = readMatFiles()
matFiles = {'file1.mat', 'file2.mat', 'file3.mat'};
%an empty array or structure to hold the data
data = [];
for i = 1:length(matFiles)
fileData = load(matFiles{i});
if isempty(data)
data = fileData;
else
data = [data; fileData];
end
end
end
You should be careful about few points when using MATLAB Function block to load data:
- Data Format: Ensure that the data format in the .mat files is consistent and compatible with how you intend to use it in Simulink.
- File Paths: If your .mat files are not in the current working directory, provide the full path to each file.
- Performance: Loading multiple .mat files can be time-consuming if the data is very large. You might consider loading the data into model workspace at model load time and then using the data as required.