import data from csv file with same format of stored data in file
Afficher commentaires plus anciens
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 commentaire
"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.
Réponses (1)
Star Strider
le 17 Mar 2024
0 votes
The data are imported and stored with their original precision. They are just displayed with 4 digits to the right of the decimal.
4 commentaires
sasan basereh
le 17 Mar 2024
Modifié(e) : sasan basereh
le 17 Mar 2024
All the decimal places (and supplied precision) are there.
Use the format function to change the way they are displayed.
Example —
T1 = array2table(randn(6,4))
format longG
T1
It is not necesary to change the format of the displayed results. This simply demonstrates that the full precision results are saved, and actually exist in the file (table ‘T1’ in this example, since I do not have your file to work with).
.
"is this for saving data to variable?"
Lets try it right now:
writematrix(10.43546,'test.txt')
M = readmatrix('test.txt')
Now lets display the data using a few different approaches:
fprintf('%.5f',M)
format long G
M
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:
Star Strider
le 17 Mar 2024
@Stephen23 — Thank you!
Catégories
En savoir plus sur Spreadsheets dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!