How to publish current m file output ONLY to pdf via inline code? (AKA, not via the Export function)
조회 수: 7 (최근 30일)
이전 댓글 표시
Hi,
I am creating a MATLAB program that will read in a data file and provide feedback based on the data within the file. (I am using fprintf for this.)
I would like to publish only the generated output (not the code) from what was run in that .m file into a PDF - but automatically. As in, the PDF is automatically generated as the final step after the user reads in the data file.
Is there a way to do that within the code itself, and not through the Export feature? I know about the publish fcn, but 1) there does not seem to be a way to indicate that only the output be published to PDF, and 2) I am not sure how to reference the current file without giving a specific file location. The reason I am trying to avoid #2 is because I'd like to be able to utilize this .m file generally across multiple computers.
댓글 수: 0
답변 (1개)
Rik
2022년 4월 11일
The code below works for me.
options = struct('format','pdf','outputDir',pwd,'showCode',false,...
'codeToEvaluate',[func2str(@test_fun) '(5)']);
publish('test_fun.m',options)
function test_fun(input)
fprintf('only this should exist in the PDF\n')
fprintf('input was %d',input)
end
I don't fully understand what you mean regarding the portability. What would be the issue with code like this?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!