How to get readmatrix to keep data to a certain amount of decimal points?

33 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2023-3-7
"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.

请先登录,再进行评论。

回答(1 个)

Arka
Arka 2023-3-7
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:

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by