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

조회 수: 4 (최근 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:

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by