codegen report.mldatx get *.m files

조회 수: 13 (최근 30일)
Tijn
Tijn 2025년 3월 11일
편집: Tijn 2025년 3월 24일
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

답변 (1개)

Harsh
Harsh 2025년 3월 21일
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
Tijn
Tijn 2025년 3월 21일
편집: Tijn 2025년 3월 24일
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?)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Generating Code에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by