Easy Question, update scatter point in loop
Ältere Kommentare anzeigen
Hi:
I just want to get the 4 vectors scatter update every time in my loop. Delete the last time points then plot then hold on to new loop.
How to do that??
Thank you.
x1{1} = [.2; .3]; x2{1} = [.3; .4]; x3{1} = [.5; .6]; x4{1} = [.6; .7]; k = 1;
for k = 1:1:50
scatter(x1{k}(1,1), x1{k}(2,1));
hold on
scatter(x2{k}(1,1), x2{k}(2,1));
hold on
scatter(x3{k}(1,1), x3{k}(2,1));
hold on
scatter(x4{k}(1,1), x4{k}(2,1));
x1{k+1} = (x1{k} + x2{k} + x4{k})/3;
x2{k+1} = (x1{k} + x2{k} + x3{k})/3;
x3{k+1} = (x2{k} + x3{k} + x4{k})/3;
x4{k+1} = (x1{k} + x3{k} + x4{k})/3;
end
Akzeptierte Antwort
Weitere Antworten (1)
Geoff Hayes
am 24 Jun. 2014
Try grabbing the handle returned from each scatter call and then deleting that on subsequent iterations. Outside the for loop declare an array to manage the scatter plot handles
% declare an array for the handles to the scatter plots
scatterHandles = [];
Now within the for loop, delete the handles if any exist
for k = 1:1:50
% delete scatter plot data from previous iteration if it exists
if ~isempty(scatterHandles)
for m=1:length(scatterHandles)
delete(scatterHandles(m));
end
end
% get the scatter plot handles for each call to scatter
hold on
scatterHandles (1) = scatter(x1{k}(1,1), x1{k}(2,1));
scatterHandles (2) = scatter(x2{k}(1,1), x2{k}(2,1));
scatterHandles (3) = scatter(x3{k}(1,1), x3{k}(2,1));
scatterHandles (4) = scatter(x4{k}(1,1), x4{k}(2,1));
% etc.
end
Try the above and see what happens!
Kategorien
Mehr zu Graphics Performance finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!