issue when creating a long vector

조회 수: 5 (최근 30일)
Clovis
Clovis 2014년 5월 16일
답변: Jos (10584) 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