issue when creating a long vector
1 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
回答(2 个)
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
0 个评论
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!