Confusion about specifiers and output
8 views (last 30 days)
Show older comments
Hi all,
I have some data file to import to matlab but I have confusion with the specifiers. I have two files attached name a and b. The content of a is saved in one row shows below,
1.0328680065922853 1.0071129674450916 1.0022185743189380
and below is the code I used to read. When I open the cell, it shows the output with 4 decimal places only but I need all the decimal places as above. Also, when I used str2double, it shows a_array is NaN.
inputfile = sprintf('a','r'); %'r' = read
fileID = fopen(inputfile,'r');
C = textscan(fileID, '%18.16f'); %
a_array = str2double([C{:}]);
The content of b is below, and I need to store the data separately by column.
1.099999440E+00 4.567727288E-01
1.099999615E+00 6.666666667E-02
and my code
inputfile = sprintf('b','r'); %'r' = read
fileID = fopen(inputfile,'r');
C = textscan(fileID, '%17E %17E'); %
temp_array = str2double([C{1}]);
Matlab shows an error
Error using textscan
Unable to parse the format character
vector at position 1 ==> %17E %17E
Unsupported format specifier '%E'.
See the documentation for TEXTSCAN
for supported formats.
I am having a confusion on these format specifier and I have chcked with the help with few different specifiers but none of them is working.
Appreciate on your help and explanation.
0 Comments
Answers (1)
Walter Roberson
on 13 Jun 2021
Edited: Walter Roberson
on 13 Jun 2021
When I open the cell, it shows the output with 4 decimal places
That does not mean that the decimal places are not stored -- it means they are not being displayed.
If you are using the variable browser to view the contents of the cell, then if you look at the top of the display, you will see a View tab. Click on that, and you will see a Format tab that has a Number Display Format drop-down and select "Long Fixed Decimal". Now the numbers in the display should be longer.
If the numbers in the display now end in "..." then you may need to drag the divider wider in order to see the full number.
You can change the default way that the Variable Browser displays numbers. In the command window, use Home -> Preferences -> MATLAB -> Variables -> Format defaut array format, and select a new format there, such as "long g".
You can change how variables show up in the command window when you disp() them, by using the format command, such as format long g
You can change the default way that the command window displays numbers (that is, the format command that will be used when you start MATLAB). Use Home -> Preferences -> MATLAB -> Command Window -> Text Display -> Numeric format:, and select a new format there, such as long g
By the way, load() should be happy to read those files. You just have to display the full decimal places if they are important to you.
0 Comments
See Also
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!