issue when creating a long vector

5 vues (au cours des 30 derniers jours)
Clovis
Clovis le 16 Mai 2014
I'm trying to interpolate a huge vector, and I got a problem. Here it is:
numel(unique(diff(1:2e-5:30))) is not equal to 1 ! That means that when I ask matlab to create a vector, it does not always have the same difference between each value.
It's pretty anoying, since in ordre to make the interp1 works, apparently I need that!
It could be related to the double, but I double that.
In any case, this is pretty annoying. What should I do?
(ps: using matlab 2012b)

Réponses (2)

Azzi Abdelmalek
Azzi Abdelmalek le 16 Mai 2014
like you mentioned it, it has to do with the ways that floating numbers are stored in memory. You can't do anything about that. Read http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F

Jos (10584)
Jos (10584) le 16 Mai 2014
You can scale the values before you use interp1. Something along these lines:
xi = 1:60e5;
x_scaled = x * 1e5 ;
yi = interp1(x_scaled, y , xi)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by