-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgencode_v2.m
45 lines (33 loc) · 1.25 KB
/
gencode_v2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
% List of model names to build
rootFolder = pwd; % Get the current folder
addpath(genpath(rootFolder)); % Add all sub-folders
HT09_Vehicle_Parameters;
modelList = {'Tire_Model_Codegen', 'Tire_Model_Codegen_Test'};
close all;
% Cell array to store the generated zip file names
zipFiles = {};
% Loop over each model
for i = 1:length(modelList)
modelName = modelList{i}; % Get the model name from the list
fprintf('Building model: %s\n', modelName); % Display progress
% Load the Simulink model
load_system(modelName);
% Build the model
slbuild(modelName)
% Close the system to free memory
close_system(modelName, 0);
% Generate the zip file name and store it in the cell array
zipFileName = strcat(modelName, '.zip');
zipFiles{end + 1} = zipFileName;
fprintf('Generated zip file: %s\n', zipFileName); % Output the zip file name
end
% Write the list of zipped files to a JSON file
jsonFileName = 'zipped_files.json';
fid = fopen(jsonFileName, 'w');
if fid == -1
error('Cannot create JSON file.');
end
% Encode the cell array directly as a JSON list
fprintf(fid, '%s\n', jsonencode(zipFiles));
fclose(fid);
fprintf('All models built and zipped successfully. JSON saved to %s.\n', jsonFileName);