Increasing speed by fixing axis and grid outside of a loop
1 view (last 30 days)
Heres a minimal example of what I mean: Axis and grid are set before the loop
Pos = [0 0];
axis([0 1 0 1]);
for i = 1:20
Pos = [0 0] + i;
%axis([0 1 0 1]);
However this will not fix the axis or the grid. Instead you have to define it inside the loop.For this minimal example it shouldn't matter, but believe it or not for larger projects I figured the program slacks a little when axis and grid are defined in the loop so how to really fix it outside?
J. Alex Lee on 1 Nov 2022
Edited: J. Alex Lee on 2 Nov 2022
I think what Torsten is getting after is: do you intend to keep the history of all the previous pairs you plotted?
But I'm going to assume you don't, and you just want to replace the plot series while keeping the other axes properties fixed, while many/most/all of them will auto-reset with the default axes property "NextPlot" value set to "replace"
One way to do it
ax = axes("XLim",[0,21],"YLim",[0,21],...
% you need NextPlot to be "add" so that the first plot you make doesn't
% undo your axes properties set in the definition, which, now that I think
% about it, is a little weird.
% return the lineseries object from plot so you can reference and alter it
ph = plot(nan,nan,"x");
pos = [0,0];
for i = 1:20
pos = pos + 1;
ph.XData = pos(1); % set the XData property of the lineseries object
ph.YData = pos(2); % set the YData property