Maximize Storage with Matlab Diary Function | Txt File Limit Solution"

In summary: In this case, the field width is 12.In summary, the conversation was about using the diary function in MATLAB to store simulation results into a txt file. The user was concerned about the file size limit and asked if there was a way to specify the size or change it. Another user suggested using the fprintf command and provided an example with specified field widths for printing values. The conversation also discussed the purpose of the field widths in the fprintf command.
  • #1
jemma
36
0
I am using the diary function to store simulation results into a txt file, e.g.

diary('TextLog.txt')

however I expect to have around 50,000 rows of data and so not all my data will be stored. Is there anything I can do to specify the size of the file? Am I right in thinking the file will only hold what is displayed in the Command Window? If so, is there a way to change this? Unless there is a different command I can use? Thanks if you can help!
 
Physics news on Phys.org
  • #2
how about writing your data to a file, no size limits...
 
  • #3
Yes thanks, I've been trying to do this using fprintf.

With the example here: http://www.mathworks.com/help/techdoc/ref/fprintf.html

B = [8.8 7.7 ; ...
8800 7700];
fprintf('X is %4.2f meters or %8.3f mm\n', 9.9, 9900, B)
MATLAB displays:

X is 9.90 meters or 9900.000 mm
X is 8.80 meters or 8800.000 mm
X is 7.70 meters or 7700.000 mm

What does the %4.2f and %8.3f do apart from rounding values to 2 and 3 decimal places respectively? i.e. what's the 4 and 8?
Thanks!
 
  • #4
The 4 and 8 specify the width of the printed output. So, for %8.3f, if you has 12.345, it would print:
Code:
  12.345
and if you had 0.1236 it would print:
Code:
   0.124
padding with whitespace so that the column width is 8.

Try this code to see how that works:
Code:
number = 12.3456789;
[COLOR="Blue"]for[/COLOR] i=1:10;
    format = sprintf([COLOR="DarkOrchid"]'%%%i.3f\n'[/COLOR], i);
    fprintf(format, number);
[COLOR="blue"]end[/COLOR]

It should produce:
Code:
12.346
12.346
12.346
12.346
12.346
12.346
 12.346
  12.346
   12.346
    12.346

MATLAB fprintf() documentation said:
  • Field width
Minimum number of characters to print. Can be a number, or an asterisk (*) to refer to an argument in the input list. For example, the input list ('%12d', intmax) is equivalent to ('%*d', 12, intmax).
 
Last edited:
  • #5


I would suggest using the "dlmwrite" function in Matlab to specify the size of the file and ensure that all data is stored. This function allows you to specify the delimiter, which can be a comma, tab, or space, and also the precision of the data. Additionally, you can use the "fclose" function to close the file and ensure that all data is saved before opening it again. Alternatively, you could also use the "save" function to save your data in a .mat file, which can hold larger amounts of data compared to a text file. I would also recommend checking the documentation for the diary function to see if there are any options for increasing the size of the file.
 

What is the Matlab Diary Function?

The Matlab Diary Function is a built-in tool that allows users to save the input and output of a Matlab session to a text file. It is commonly used to document and track the progress of a project or analysis.

How does the Matlab Diary Function help maximize storage?

The Matlab Diary Function helps maximize storage by saving the output of a Matlab session to a text file rather than storing it in the workspace. This prevents the workspace from becoming cluttered and using up unnecessary storage space.

What is the default text file limit for the Matlab Diary Function?

The default text file limit for the Matlab Diary Function is 1 MB. This means that once the text file reaches a size of 1 MB, the diary function will stop recording the session's input and output.

How can the text file limit be increased?

The text file limit can be increased by using the "diary('filename.txt', 'append')" command instead of just "diary('filename.txt')". This will append new session data to the existing text file instead of creating a new one every time.

Can the Matlab Diary Function be turned off?

Yes, the Matlab Diary Function can be turned off by using the "diary off" command. This will stop the recording of the session's input and output and close the diary file.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
861
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
9K
Back
Top