How to get readmatrix to keep data to a certain amount of decimal points?
27 views (last 30 days)
Show older comments
I am using readmatrix to pull data from a .csv that data points such as 2022.375. However, my readmatrix for the file turns it into 1.0e+03 * 2.0224. How can I make readmatrix keep the accuracy I need it to?
1 Comment
Stephen23
on 7 Mar 2023
"However, my readmatrix for the file turns it into 1.0e+03 * 2.0224."
No, READMATRIX does not "turn" your data into anything like that. You are confusing how numeric data are displayed with what data are stored in memory. Not the same things at all (although they are related to each other). READMATRIX imports all of your data correctly and it is all stored correctly. How it is displayed depends on your FORMAT settings, which by default are SHORT, i.e. four digits after the decimal point. But you can change that.
"How can I make readmatrix keep the accuracy I need it to?"
It already does.
If you want to change how numeric data are displayed then change the FORMAT, e.g. use LONG G.
Answers (1)
Arka
on 7 Mar 2023
Hi,
1.0e+03 * 2.0224 is just another way of representing 2022.375. The data is being stored in the format it was read from the CSV in, and it is being displayed in the format that we have specified.
In MATLAB, there are multiple ways of displaying values. 1.0e+03 * 2.0224 is in short e format, and 2022.375 is in long format.
To know more about the format command, please refer to the MathWorks documentation below:
0 Comments
See Also
Categories
Find more on Get Started with MATLAB 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!