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

142 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:
mov = VideoReader('pendulo.mp4'); % estrutura com video
nFrames = mov.NumFrames; % numero de frames
framerate = mov.FrameRate; % numero de frames por segundo
dtframes=1/framerate; %tempo entre frames
i=1; t=0; tf=nFrames*dtframes; dt=10*dtframes;
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)));
[x(i) ,y(i)]=ginput(1);
end
save ('dados.mat', 'x', 'y');
load ('dados.mat', 'x', 'y');
end
and the code I use for the spline function is this one:
load ('dados.mat', 'x', 'y');
xx = linspace(0,500,100);
yy = spline(x,y,xx);
figure;
plot(x, y, 'ro');
hold on;
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
dpb
dpb on 18 Jun 2021
Post a complete working example here that illustrates the problem, not on some external site.
Need the data mostly, of course; nothing we can do without it to diagnose anything...

Sign in to comment.

Accepted Answer

dpb
dpb on 18 Jun 2021
>> load dados
>> whos x y
Name Size Bytes Class Attributes
x 1x58 464 double
y 1x58 464 double
>> 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 =
Columns 1 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
Columns 19 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 =
Columns 1 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
Columns 31 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
Edited: Hélio Filho on 19 Jun 2021
Unfortunately my assignment requires me to use the spline tool. I have since given up on this, and am working with less points. I asked my professor and he told me to interpolate y with t so I don't get duplicate values. Not sure what he means by this though.
Even so, you've put a lot of work into this, thank you for the help!
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!

Categories

Find more on Linear Algebra in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!