CSV Vector Values Read in With Too Few Decimal Places

32 Ansichten (letzte 30 Tage)
Wyatt Morris
Wyatt Morris am 21 Jul. 2021
Beantwortet: Walter Roberson am 21 Jul. 2021
Hi there,
I am currently reading in a .csv file with two columns of values in order to perform a 1/3 octave smoothing of them. All of these values are in the .csv file to 13 decimal places; however, when they are read into MatLab is appears as if they are being rounded to 4 decimal places. Because of this. the functions I am using in my analysis are telling me that the values in my vector are not spaced regularly, even though they are when at 13 decimal places. Currently, I am just using the readmatrix command to read in my necessary .csv files.
Is there a way to determine how many decimal places MatLab recognizes from the .csv file?
Thanks!

Antworten (1)

Walter Roberson
Walter Roberson am 21 Jul. 2021
Give the command
format long g
Now ask to display the data you read in. I think you will find that it has the full 13 digits.
Now take your matrix, say M, and use
unique(diff(diff(M)))
and you will see that your data really is not spaced evenly.
I suggest you
new_times = linspace(old_times(1), old_times(end), length(old_times));
newdata = interp1(old_times, old_data, new_times);
I also recommend that you use
Preferences -> Command Window -> Text display -> Numeric format
controls the default "format" command for your session; this is which format will be used at the command window each time you start MATLAB
Preferences -> Variables -> Format -> Default array format:
controls the default "format" that is used for the Variable Browser
I suggest changing both of those to "long g", so that you are not mislead by the default way that MATLAB displays values, which is different than how MATLAB stores values.

Kategorien

Mehr zu Entering Commands finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by