Error using chckxy: The first input must contain unique values, while using only unique values
142 views (last 30 days)
Show older comments
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
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...
Accepted Answer
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
More Answers (1)
See Also
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!