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

1 回表示 (過去 30 日間)
sasan basereh
sasan basereh 2024 年 3 月 17 日
コメント済み: Star Strider 2024 年 3 月 17 日
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 件のコメント
Stephen23
Stephen23 2024 年 3 月 17 日
編集済み: Stephen23 2024 年 3 月 17 日
"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.

サインインしてコメントする。

回答 (1 件)

Star Strider
Star Strider 2024 年 3 月 17 日
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 件のコメント
Stephen23
Stephen23 2024 年 3 月 17 日
編集済み: Stephen23 2024 年 3 月 17 日
"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:
Star Strider
Star Strider 2024 年 3 月 17 日
@Stephen23 — Thank you!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStandard File Formats についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by