Why does Matlab care how many output arguments I specify?
Show older comments
I've never known any native Matlab function to place a requirement on the number of ouput arguments that I request. For some reason getpoints() is an exception. Why does it care?
h = animatedline;
axis([0,4*pi,-1,1])
x = linspace(0,4*pi,1000);
y = sin(x);
for k = 1:length(x)
addpoints(h,x(k),y(k));
drawnow
end
[X,~] = getpoints(h)
X=getpoints(h)
1 Comment
Chuguang Pan
on 20 Sep 2026 at 7:12
Answers (1)
help getpoints
Apparently MathWorks chose to make it a requirement to match its stated purpose to retrieve the points that make up an animated line object and that while the user may have reasons for only retrieving one dimension, the values obtained wouldn't be sufficient to recreate the object. Simply an internal design decision since there would be no fundamental reason that the function itself couldn't behave in a fashion consistent with overall MATLAB practice.
It is at least highly unusual (if not totally unique?) behavior, granted. Only somebody inside and on the design and implementation team would be able to say more definitively, of course. :>)
ADDENDUM:
Wonder if it knows enough depending upon the animated line itself?
h = animatedline;
N=10;
for k = 1:N
addpoints(h,rand,rand,rand);
drawnow
end
view(-37.5,30)
grid on
[X,Y]=getpoints(h)
No, it apparently only enforces >1, not as many as are actually required for the animatedline object itself which doesn't expose whether it was created with two or three coordinates; internally one would guess probably always three, just default for the third if not given.
get(h)
ADDENDUM SECOND
I notice the documentation doesn't note anywhere that at least the two outputs are required. I don't know that the behavior is sufficient to justify an enhancement request to modify its behavior, but it does look as though a documentation update would be in order.
2 Comments
Torsten
on 20 Sep 2026 at 14:35
Quite inconsistent that there is an error message with one output argument and 2d-data as input and no error message with two output arguments and 3d-data as input ...
Indeed, why I tried the test...using struct(h) on the handle and poking around didn't immediately find a way to determine about the dimensionality. Although somewhere in the bowels there has to be the associated data, it isn't readily visible outside using the associated getpoints function. It does seem on the surface to be a totally superfluous requirement.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
