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

  • Context: MATLAB 
  • Thread starter Thread starter jemma
  • Start date Start date
  • Tags Tags
    Function Matlab
Click For Summary

Discussion Overview

The discussion revolves around the use of the MATLAB diary function for storing simulation results in a text file, particularly addressing concerns about file size limitations and exploring alternative methods for data storage. Participants are examining both the diary function and the fprintf command for output formatting.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant is concerned that the diary function may not store all data due to a limit on the number of rows and questions whether the file only holds what is displayed in the Command Window.
  • Another participant suggests writing data to a file without size limits as an alternative approach.
  • A participant shares their attempt to use fprintf for outputting data and seeks clarification on the formatting specifiers %4.2f and %8.3f, specifically what the numbers represent beyond rounding.
  • A later reply explains that the numbers in the format specifiers indicate the width of the printed output, providing an example of how different widths affect the display of numbers.
  • Further clarification is provided on the concept of field width in formatting, including the use of an asterisk to refer to an argument in the input list.

Areas of Agreement / Disagreement

Participants do not appear to reach a consensus on the best method for storing large amounts of data, as multiple approaches are discussed without resolution on which is superior.

Contextual Notes

There are limitations regarding the assumptions about the diary function's capabilities and the specifics of data formatting with fprintf that remain unresolved.

jemma
Messages
35
Reaction score
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
how about writing your data to a file, no size limits...
 
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!
 
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;
for i=1:10;
    format = sprintf('%%%i.3f\n', i);
    fprintf(format, number);
end

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:

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K