2
votes

I'm learning MATLAB and for my homework am supposed to use the diary feature to save a file from the command window. I used the following code,

%% 2.21

clc
clear

diary( 'degrees.dat' )

columnOne = linspace(0, 180, 8);
columnTwo = columnOne .* (pi / 180);
D_to_R = [columnOne', columnTwo']

diary off

clc
clear

load ( 'degrees.dat' )`

and got the error:

Error using load Number of columns on line 3 of ASCII file degrees.dat must be the same as previous lines.

I put the above code in the editor window but tried putting it directly in the command window and it didn't make a difference. The code up until loading the saved file seems to work fine and I can't see a difference in number of columns like the error indicates. Any ideas?

1
diary puts all text from the command window in an ASCII file. load is used for loading variables, typically from a file in .mat format, or optionally from ASCII with a specific format, which is not what you get in your diary file. The diary file is not normally meant to be processed by Matlab. What did you expect load('degrees.dat') to do? - Luis Mendo

1 Answers

0
votes

You are using diary correctly. However, your use of load is incorrect, and most likely unneeded based on the problem at hand. You've shown that you can save a file with 'diary'.

If you want to show the contents of your diary as stored in the file degrees.dat in the command window you can type, into the command window: type degrees.dat or type('degrees.dat').

Similarly, if you want to open it in the edit window you can use edit('degrees.dat') or edit degrees.dat