codegen report.mldatx get *.m files
8 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Harsh
2025 年 3 月 21 日
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 件のコメント
Harsh
2025 年 3 月 21 日
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
参考
カテゴリ
Help Center および File Exchange で Generating Code についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!