issue when creating a long vector

5 次查看(过去 30 天)
Clovis
Clovis 2014-5-16
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)

回答(2 个)

Azzi Abdelmalek
Azzi Abdelmalek 2014-5-16
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) 2014-5-16
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)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by