Error using chckxy: The first input must contain unique values, while using only unique values

217 views (last 30 days)
Hello,
So I have to spline some data I acquired with ginput. While using spline, I get the following error
Error using chckxy
The first input must contain unique values.
At first I thought I had accidently selected two or more equal points, so I tried selecting random points which I knew were different for sure, and I still get the same error.
Then, I get another error in spline itself:
[x,y,sizey,endslopes] = chckxy(x,y);
Keep in mind this is not even part of my code, this is just matlab's function.
The code I use to acquire the points is this one:
  1. mov = VideoReader('pendulo.mp4'); % estrutura com video
  2. nFrames = mov.NumFrames; % numero de frames
  3. framerate = mov.FrameRate; % numero de frames por segundo
  4. dtframes=1/framerate; %tempo entre frames
  5. i=1; t=0; tf=nFrames*dtframes; dt=10*dtframes;
  6. if ~exist('dados.mat','file')
  7. while (t <= tf)
  8. mov.CurrentTime=t; frame=readFrame(mov); image(frame); drawnow
  9. tv(i)=t; t=t+dt; i=i+1; title(strcat('Frame ',num2str(i)));
  10. [x(i) ,y(i)]=ginput(1);
  11. end
  12. save ('dados.mat', 'x', 'y');
  13. load ('dados.mat', 'x', 'y');
  14. end
and the code I use for the spline function is this one:
  1. load ('dados.mat', 'x', 'y');
  2. xx = linspace(0,500,100);
  3. yy = spline(x,y,xx);
  4. figure;
  5. plot(x, y, 'ro');
  6. hold on;
  7. plot(xx, yy, 'b', 'LineWidth', 1.5);
I don't understand why I get an error at MATLAB's own function, and why I get the "must contain unique values" error, even though they are unique.
The data is annexed as 'dados.mat'.
2 Comments

Sign in to comment.

Accepted Answer

dpb
dpb on 18 Jun 2021
>> load dados
>> whos xy
Name大小BytesClassAttributes
x1x58464double
y1x58464double
>> numel(unique(x))
ans =
36
>> numel(unique(y))
ans =
57
>>
Well, clearly your data are NOT unique...you've only got 36 x values and 57 (closer, anyways) y values.
>> xu
xu =
Columns1 through 18
0 15.7431 16.7265 17.7099 18.6934 19.6768 20.6602 47.2127 68.8481 86.5497 87.5331 89.5000 91.4669 92.4503 94.4171 95.4006 103.2680 133.7541
Columns19 through 36
162.2735 163.2569 166.2072 167.1906 168.1740 169.1575 170.1409 171.1243 173.0912 189.8094 210.4613 222.2624 224.2293 225.2127 226.1961 227.1796 228.1630 262.5829
>> histc(x,xu)
ans =
Columns1 through 30
1 3 3 6 1 3 1 1 1 1 1 2 1 2 2 2 1 1 2 1 3 2 1 1 1 1 1 1 1 2
Columns31 through 36
1 2 2 1 1 1
>>
However you thought you generated unique values clearly didn't work as you presumed...
Above is scatter plot of the point cloud; the filled values are those that are unique in x; I didn't add y but the this shows the problem.
3 Comments
Hélio Filho
Hélio Filho on 19 Jun 2021
So I've been thinking, maybe I should use the variable t as my x data and I should acquire the y variable from the ginput function. As this is a movie, t is constantly evolving, so I can guarantee that there will be no two t values that are the same.
However, while changing the acquiring to t, like this:
i=1; t=0; tf=nFrames*dtframes; dt=10*dtframes;%% 17 frames ao invés de 58
if~exist('dados.mat','file')
while(t <= tf)
mov.CurrentTime=t; frame=readFrame(mov); image(frame); drawnow
tv(i)=t; t=t+dt; i=i+1; title(strcat('Frame ',num2str(i)));
[t(i) ,y(i)]=ginput(1);
end
save ('dados.mat','t','y');
load ('dados.mat','t','y');
end
It only allows me to take in 1 value; after that it automatically uses splice. I don't understand why, since i is evolving all the time inside the while, and therefore i should have t(i+1) all the time. Is t not representing time here?

Sign in to comment.

More Answers (1)

Hélio Filho
Hélio Filho on 18 Jun 2021
So apparently I had two different points with the same X value, I had to decrease the number of points. This solution is not optimal, since I lose data, but if any of you have a better one I will take it!

Tags

s manbetx 845

Community Treasure Hunt

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

Start Hunting!