How to display command lines from a function?

조회 수: 3 (최근 30일)
Mats van Es
Mats van Es 2016년 9월 27일
댓글: Mats van Es 2016년 9월 28일
Hi all,
Currently I am trying to improve my data administration. For each data file I create with my functions, I want to have a text file with all the commands that caused the creation of the data file. This way, I can always look back at a file and see which parameters and commands were used, thereby improving reproducibility and verification. Right now I use matlabs 'diary' to save all the command window output. However, the command lines of a function don't appear here. So what I am looking for is to do just that: print my function's command lines to the command window (similar to what happens if you run code with F9), so that the text is saved by 'diary'.
Thanks!

채택된 답변

Massimo Zanetti
Massimo Zanetti 2016년 9월 27일
Use the fgets to read each line of a script and print it.
fid = fopen('matlab_file.m');
tline = fgets(fid);
while ischar(tline)
disp(tline)
tline = fgets(fid);
end
fclose(fid);
  댓글 수: 1
Mats van Es
Mats van Es 2016년 9월 28일
Thanks a lot! Does exactly what I was looking for :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by