Warning message when using Patch in 2015 matlab?

1 次查看(过去 30 天)
Hello I have a question about patch.
I have this code working fine in Matlab2014
clear;clc;close all;
box=[0 20 20 0; 0 0 20 20];
hold on;
h.box= patch(0,0,'b','erasemode','xor');
xlim([-10,1000]); ylim([-10,1000])
axis equal
for i = 1: 1000
xb=box+i;
set(h.box, 'xdata', xb(1,:), 'ydata', xb(2,:))
drawnow;
end
When i started running it on 2015 i am getting this kind of warning
Warning: The EraseMode property is no longer supported and will error in a
future release. Use the ANIMATEDLINE function for animating lines and
points instead of EraseMode 'none'. Removing instances of EraseMode set to
'normal', 'xor', and 'background' has minimal impact.
> In test (line 9)
So i decided to try and update the code according to the advise given by the warning
here is my new code
clear;clc;close all;
box=[0 20 20 0; 0 0 20 20];
hold on;
h.box = animatedline('MaximumNumPoints',80,'Color','b');
xlim([-10,1000]); ylim([-10,1000])
axis equal
for i = 1: 1000
xb=box+i;
addpoints(h.box,xb(1,:),xb(2,:));
drawnow;
end
Still not what i wanted it to look like, I wanted it to be functioning exactly as my 2014 code any advise what to do?

采纳的回答

Walter Roberson
Walter Roberson 2015-6-27
clear; clc; close all;
box=[0 20 20 0; 0 0 20 20];
h.box= patch(0,0,'b');
xlim([-10,1000]); ylim([-10,1000]);
axis equal
drawnow();
set(gca, 'xlimmode', 'manual', 'ylimmode', 'manual')
hold on;
for i = 1: 1000
xb=box+i;
set(h.box, 'xdata', xb(1,:), 'ydata', xb(2,:))
drawnow;
end
I made this code bug-for-bug compatible because you asked for it to function exactly the same as your R2014 code. In your code, the "axis equal" overrode the xlim([-10,1000]) and ylim([-10,1000]) giving you limits of -1000 to +1000. The axis equal also set the xlimmode and ylimmode to auto which is why if you just remove the drawmode parameter with your code you would get the unexpected scrolling x axis. The effect of "axis equal" on the xlim and ylim in R2014a can depend upon the commands that follow before the object is rendered and upon the figure position, so I force the object to render before turning off automatic axis limits so that the x axis limits are set to [-640.286298568507, 640.286298568507] in a bug-for-bug compatible way.
I would suggest that you revise the code to do what your code appears to want to do, not what your current code does.
box=[0 20 20 0; 0 0 20 20];
h.box= patch(0,0,'b');
xlim([-10,1000]); ylim([-10,1000]);
hold on;
for i = 1: 1000
xb=box+i;
set(h.box, 'xdata', xb(1,:), 'ydata', xb(2,:))
drawnow;
end
Without the "axis equal" after you have already set your xlim and ylim, the limits become exactly what you set and remain that way because xlim() and ylim() set xlimmode and ylimmode to 'manual' (no need to force them back to manual after "axis equal" has reset them if you skip the "axis equal")

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by