Interp1 is not working after applying unique because of rounding off
조회 수: 2 (최근 30일)
이전 댓글 표시
Govind Sankar Madhavan Pillai Ramachandran Nair
2025년 6월 20일
댓글: Govind Sankar Madhavan Pillai Ramachandran Nair
2025년 6월 20일
I have a double array with many values. The first value is 3.569990000000001, the next multiple values is 3.570000000000001, then comes 3.570010000000001 and it works like this. I can see only these long values which i click on that cell, otherwise every value is being displayed as 3.57. Now I applied unique, so the multiple 3.570000000000001 is removed and there is now only one 3.570000000000001 and again and so on, but still all values are seen as 3.57. So if compared the first two values to see if it equal it is showing that they are not equal even though me as the user sees both values as 3.57. Now here comes the problem. I need to use interp1 on these values, but here interp1 is not reading them as 3.569990000000001 and 3.570000000000001. Interp1 is reading both of them as 3.57 and is giving me an error saying values need to be unique. I dont know what to do. I tried googling like converting to format long or something like that, i couldnt find anything. What can I do. Thank you.
댓글 수: 0
채택된 답변
추가 답변 (1개)
Steven Lord
2025년 6월 20일
I need to use interp1 on these values, but here interp1 is not reading them as 3.569990000000001 and 3.570000000000001. Interp1 is reading both of them as 3.57 and is giving me an error saying values need to be unique.
Please show a small sample of code including the full and exact text of the error message. That's not the behavior I'm seeing when I hard-code the values you say are in your vector. If that code requires some data, please also show a small sample of data we can use to run that code.
x = [3.569990000000001, 3.570000000000001]
uniqueX = unique(x)
y = [2, 4]
z = interp1(x, y, 3.57)
As Torsten said, if you want to remove the values that are "close enough" use uniquetol.
difference = diff(x)
tolerance = 1e-4;
uniqueXCloseEnough = uniquetol(x, tolerance)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!