Diary command does not capture command window results from a script file.

11 visualizaciones (últimos 30 días)
Glenn
Glenn el 20 de Oct. de 2022
Comentada: Rik el 22 de Oct. de 2022
I'm looking to use the diary feature to save the command window results obtained after running a script file. The diary file is empty after initiating the diary {filename} command and then executing the m-file script. My expectation is that everything seen and displayed in the command window is captured in the diary file. I am curently using the MATLAB online resource to run my m-file scripts.
Is capturing command window results generated from a m-file script not possible with the diary command?
  3 comentarios
Rik
Rik el 20 de Oct. de 2022
I don't see anything in the limitations section of the documentation regarding Matlab Online.
Can you attach the script? That way we can have a look wether anything in the script could possibly interfere.
Glenn
Glenn el 20 de Oct. de 2022
Editada: Glenn el 20 de Oct. de 2022
Thank you for responding. Attached is an example of the script I am using with the expectation to capture the command window results in a diary file. These are the steps that I'm doing when using the diary command.
  1. Create m-file script with disp () commands to describe and document results that are displayed in the command window.
  2. When I'm satisfied with my script file, I clear the screen and all variables from the command window - clc, clear
  3. From the command window I start a diary session - diary capture.txt
  4. run the m-file script - resutls are displayed in command window
  5. diary off - to end the diary capturing feature
  6. open capture.txt file - File content is empty
  7. only thing captured in file is: diary off
I also added the diary command in the opening of the script file to begin the capture and ended the script with the diary off command. The diary file is created with the same results - empty

Iniciar sesión para comentar.

Respuestas (2)

Rik
Rik el 20 de Oct. de 2022
Even setting a full path for the diary file didn't work.
DiaryFileName = fullfile(tempdir,'myFile.txt');
diary(DiaryFileName)
The only way I can think of to capture this is with evalc (which you should never use otherwise):
DiaryContent = evalc('Class_Week7A');
fid = fopen( DiaryFileName ,'w');
fprintf(fid,'%s',DiaryContent);
fclose(fid);
type(DiaryFileName)
name StudentID: 1234567890 Course: class-01 FALL 2022 Lab: week 07a_lecture examples =================================================================== =================================================================== Table3.5 - Entry #01 The vector x=[1,5,3] and we are looking for the max value x = 1 5 3 MATLAB found the max value to be ans = 5 =================================================================== =================================================================== Table3.5 - Entry #02 The matrix x=[1,5,3; 2,4,6] and we are looking for the max value in this matrix x = 1 5 3 2 4 6 MATLAB found the max value to be ans = 2 5 6 This represents the maximum value for the colummns of matrix x =================================================================== =================================================================== Table3.5 - Entry #0x The x matrix is: x = 1 5 3 2 4 6 The y matrix is: y = 10 2 4 1 8 7 The max values for x and y matrices is: ans = 10 5 4 2 8 7 ===================================================================
You should never use eval (or evalc). In this case the better way would be to incorporate an actual logging system, where you replace disp with fprintf.

Glenn
Glenn el 22 de Oct. de 2022
Thank you to everyone who took the time to assist with the issues I'm having with the diary command using the MATLAB Online resource. Looks like this a verified issue that Mathworks is looking into. See below for the response I received from the Mathworks Technical Support Department.
================================================================
Hello Glenn,
Thank you for your patience as I investigated this behavior.
Unfortunately, this is a known issue. The "diary" function does not work as expected in MATLAB Online and only logs user inputs, not command line output. Our developers have been made aware of this issue and are considering it for a future release. I apologize for any inconvenience this has caused you.
Some potential workarounds I can suggest to you would be to either use a locally installed version of MATLAB if possible or to manually copy the output into a text file.
I am going to close this case, but if you have further questions about this issue you can reply to this email and I will be happy to reopen it.
Sincerely,
MathWorks Technical Support Department
  1 comentario
Rik
Rik el 22 de Oct. de 2022
Please mark either answer as accepted answer. If you pick your own answer and my answer helped you, please consider giving it an upvote.

Iniciar sesión para comentar.

Categorías

Más información sobre Entering Commands en Help Center y File Exchange.

Etiquetas

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