import data from csv file with same format of stored data in file

5 visualizaciones (últimos 30 días)
sasan basereh
sasan basereh el 17 de Mzo. de 2024
Comentada: Star Strider el 17 de Mzo. de 2024
hi.
i have csv file with arraay of data stored in it such as date, time & values. values are stored with 5 decimal point format. (such as 10.43546)
i want to import it to matlab with readtable. but when importing done, data is stored in 4 decimal point format. (such as 10.4355)
in which way i can import data of csv file & store specific columns with desired format (such as 5 decimal point format).
with thanks
  1 comentario
Stephen23
Stephen23 el 17 de Mzo. de 2024
Editada: Stephen23 el 17 de Mzo. de 2024
"but when importing done, data is stored in 4 decimal point format."
I doubt that.
Most likely you are confusing the displaying of data with what data are stored in memory. Two different things.
"import data from csv file with same format of stored data in file"
Numeric data classes do not store any format information, so what you are asking for ... does not make much sense in terms of how computers actually store numeric data. In the unlikely event that you really need the exact format then you would need to store the value as text... which is then basically useless for doing any calculations on.

Iniciar sesión para comentar.

Respuestas (1)

Star Strider
Star Strider el 17 de Mzo. de 2024
The data are imported and stored with their original precision. They are just displayed with 4 digits to the right of the decimal.
See the format function for options on changing it to display what is actually being imported.
  4 comentarios
Stephen23
Stephen23 el 17 de Mzo. de 2024
Editada: Stephen23 el 17 de Mzo. de 2024
"is this for saving data to variable?"
Lets try it right now:
writematrix(10.43546,'test.txt')
M = readmatrix('test.txt')
M = 10.4355
Now lets display the data using a few different approaches:
fprintf('%.5f',M)
10.43546
format long G
M
M =
10.43546
So far the only problem seems to be that you are confusing how data is displayed with the actual data stored in memory. They are not the same thing:

Iniciar sesión para comentar.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by