codegen report.mldatx get *.m files
4 views (last 30 days)
Show older comments
So someone has generated c code, we do not have the *.m files, but they are in the report.mldatx file which came with the code generation
we are 50% there, but are lookinig for code to do step 1
open report.mldatx with Matlab and click Export Report Information -> with name reportInfo
Even better if we can use a Matlab native function for this, due to be more robust for version update etc
What seems to work:
% by hand open report.mldatx with Matlab and click Export Report Information -> with name reportInfo
% Assuming 'reportInfo' contains the InputFiles
inputFiles = reportInfo.InputFiles;
% Check if inputFiles is not empty
if ~isempty(inputFiles)
% Save each InputFile as .m file using the function name
for i = 1:length(inputFiles)
% Extract the first line to get the function name
fileContent = inputFiles(i).Text;
firstLine = strsplit(fileContent, '\n');
% Check if the first line is not empty
if ~isempty(firstLine)
% Enhanced regex to match function definitions with multiple outputs
functionNameMatch = regexp(firstLine{1}, 'function\s+\[*.*\]*\s*=\s*(\w+)', 'tokens');
% Check if a function name was found
if ~isempty(functionNameMatch)
functionName = functionNameMatch{1}{1};
% Define the filename using the function name
filename = sprintf('%s.m', functionName);
% Write the content to the .m file
fid = fopen(filename, 'w');
fprintf(fid, '%s', fileContent);
fclose(fid);
else
warning('No function name found in the first line of InputFile %d', i);
end
else
warning('First line is empty in InputFile %d', i);
end
end
else
warning('InputFiles is empty in reportInfo');
end
0 Comments
Answers (1)
Harsh
on 21 Mar 2025
The "coder.ReportInfo" properties contain information about code generation settings, input files, generated files, code generation messages, code insights, and build logs. A "coder.ReportInfo" object can only be created programmatically while doing the code generation by using the "codegen" command with the "-reportinfo" option at the command line. Specify the variable name after the "-reportinfo" option.
codegen myFunction -reportinfo info
For more information, please refer to the following documentation - https://www.mathworks.com/help/releases/R2022b/coder/ug/report-information-object.html?searchHighlight=coder.report&s_tid=srchtitle_support_results_3_coder.report
3 Comments
Harsh
on 21 Mar 2025
As per the "Coder.ReportInfo" documentation page, there is no direct way to create this object. You have to export the code generation report to a variable in base worspace. Documentation - https://www.mathworks.com/help/coder/ref/coder.reportinfo-properties.html#:~:text=You%20do%20not%20directly%20create%20a%20coder.ReportInfo%20object.%20When%20you%20export%20code%20generation%20report%20information%20to%20a%20variable%20in%20your%20base%20MATLAB%C2%AE%20workspace%2C%20a%20coder.ReportInfo%20object%20is%20automatically%20created%20that%20contains%20this%20information
See Also
Categories
Find more on Generating Code in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!