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

28 vues (au cours des 30 derniers jours)
Steven
Steven le 7 Mar 2023
Réponse apportée : Arka le 7 Mar 2023
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 commentaire
Stephen23
Stephen23 le 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.

Connectez-vous pour commenter.

Réponses (1)

Arka
Arka le 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:

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by