codegen report.mldatx get *.m files

11 visualizaciones (últimos 30 días)
Tijn
Tijn el 11 de Mzo. de 2025
Editada: Tijn el 24 de Mzo. de 2025
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

Respuestas (1)

Harsh
Harsh el 21 de Mzo. de 2025
Hi @Tijn,
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
  3 comentarios
Tijn
Tijn el 21 de Mzo. de 2025
Editada: Tijn el 24 de Mzo. de 2025
I understand that with codegen function this is output
But there is also the generated file report.mldatx
Matlab has a viewer to interpret and show the contens and since this viewer also can Export Report Information to a variable
And this variable has InputFiles which is the source code *.m files
So if the Matlab viewer tool can do the Export Report Information to variable,
we hope we can do that in code too ; ))
(This because we from embedded software get the generated code + report file)
So maybe my question is a feature request? (Or maybe there is a possibility outside of the mentioned documentation?)

Iniciar sesión para comentar.

Categorías

Más información sobre Generating Code en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by