Email: helpdesk@telkomuniversity.ac.id

This Portal for internal use only!

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Categories
  • Microsoft
    • Microsoft Apps
    • Office
    • Operating System
    • VLS
    • Developer Tools
    • Productivity Tools
    • Database
    • AI + Machine Learning
    • Middleware System
    • Learning Services
    • Analytics
    • Networking
    • Compute
    • Security
    • Internet Of Things
  • Adobe
  • Matlab
  • Google
  • Visual Paradigm
  • WordPress
    • Plugin WP
    • Themes WP
  • Opensource
  • Others
More Categories Less Categories
  • Get Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • My Account
    • Download
    • Cart
    • Checkout
    • Login
  • About Us
    • Contact
    • Forum
    • Frequently Questions
    • Privacy Policy
  • Forum
    • News
      • Category
      • News Tag

iconTicket Service Desk

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Menu
  • Home
    • Download Application Package Repository Telkom University
    • Application Package Repository Telkom University
    • Download Official License Telkom University
    • Download Installer Application Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • All Pack
    • Microsoft
      • Operating System
      • Productivity Tools
      • Developer Tools
      • Database
      • AI + Machine Learning
      • Middleware System
      • Networking
      • Compute
      • Security
      • Analytics
      • Internet Of Things
      • Learning Services
    • Microsoft Apps
      • VLS
    • Adobe
    • Matlab
    • WordPress
      • Themes WP
      • Plugin WP
    • Google
    • Opensource
    • Others
  • My account
    • Download
    • Get Pack
    • Cart
    • Checkout
  • News
    • Category
    • News Tag
  • Forum
  • About Us
    • Privacy Policy
    • Frequently Questions
    • Contact
Home/Matlab/Refresh overlaid plots without “hold on/hold off” in each loop iteration

Refresh overlaid plots without “hold on/hold off” in each loop iteration

PuTI / 2025-03-14
Refresh overlaid plots without “hold on/hold off” in each loop iteration
Matlab News

I have a script with multiple figures that are updated in a for loop using their figure and axes handles. One of the figures is a pair of scatterplots overlaid on each other. I need both these concurrent scatterplots cleared at the beginning of each iteration, before updating with the new data for both of them. When using the "hold on" command to overlay the scatterplots on a single figure, I am unable to clear the second one for the next loop iteration using the "set" command. Here’s a snippet of my code:
for i = 1 to N

% Figure 1 (with overlaid scatterplots)
if ~(exist(fig1))
fig1 = figure;
f1 = subplot(2,1,1,’Parent’,fig1);
%% Overlay 2 scatterplots in this subplot %%
sc1 = scatter(x1,y1,’b’,’Parent’,f1);
hold on;
scatter(x2,y2,’r’,’Parent’,f1);
% Other subplots %
else
figure(fig1)
% Update new info for both scatterplots and overlay them in the first subplot
set(sc1,’XData’,x1,’YData’,y1,’CData’,repmat(sc1.CData(1,:)),’Parent’,f1);
hold on;
scatter(x2,y2,’r’,’Parent’,f1);
% Other subplots %
end

% Plot some other figure
if ~(exist(fig2))
fig2 = figure;
ax = axes(‘Parent’,fig1);
% Plot Figure 2
else
figure(fig2)
% Figure 2 plots and legends using ax
end

end
The problem is, the second scatterplot does not get cleared in the next loop iteration when set(sc1,…) is called. I tried the cla(f1,’reset’) command, but that deletes all the XData, YData variables, which I need to exist in order to update.
I think the "hold on" is creating the persistence issue, but adding "hold off" after the second scatter just clears the entire subfigure including axes.
Is there some other way to accomplish the goal of overlaid scatterplots refreshed in each loop?I have a script with multiple figures that are updated in a for loop using their figure and axes handles. One of the figures is a pair of scatterplots overlaid on each other. I need both these concurrent scatterplots cleared at the beginning of each iteration, before updating with the new data for both of them. When using the "hold on" command to overlay the scatterplots on a single figure, I am unable to clear the second one for the next loop iteration using the "set" command. Here’s a snippet of my code:
for i = 1 to N

% Figure 1 (with overlaid scatterplots)
if ~(exist(fig1))
fig1 = figure;
f1 = subplot(2,1,1,’Parent’,fig1);
%% Overlay 2 scatterplots in this subplot %%
sc1 = scatter(x1,y1,’b’,’Parent’,f1);
hold on;
scatter(x2,y2,’r’,’Parent’,f1);
% Other subplots %
else
figure(fig1)
% Update new info for both scatterplots and overlay them in the first subplot
set(sc1,’XData’,x1,’YData’,y1,’CData’,repmat(sc1.CData(1,:)),’Parent’,f1);
hold on;
scatter(x2,y2,’r’,’Parent’,f1);
% Other subplots %
end

% Plot some other figure
if ~(exist(fig2))
fig2 = figure;
ax = axes(‘Parent’,fig1);
% Plot Figure 2
else
figure(fig2)
% Figure 2 plots and legends using ax
end

end
The problem is, the second scatterplot does not get cleared in the next loop iteration when set(sc1,…) is called. I tried the cla(f1,’reset’) command, but that deletes all the XData, YData variables, which I need to exist in order to update.
I think the "hold on" is creating the persistence issue, but adding "hold off" after the second scatter just clears the entire subfigure including axes.
Is there some other way to accomplish the goal of overlaid scatterplots refreshed in each loop? I have a script with multiple figures that are updated in a for loop using their figure and axes handles. One of the figures is a pair of scatterplots overlaid on each other. I need both these concurrent scatterplots cleared at the beginning of each iteration, before updating with the new data for both of them. When using the "hold on" command to overlay the scatterplots on a single figure, I am unable to clear the second one for the next loop iteration using the "set" command. Here’s a snippet of my code:
for i = 1 to N

% Figure 1 (with overlaid scatterplots)
if ~(exist(fig1))
fig1 = figure;
f1 = subplot(2,1,1,’Parent’,fig1);
%% Overlay 2 scatterplots in this subplot %%
sc1 = scatter(x1,y1,’b’,’Parent’,f1);
hold on;
scatter(x2,y2,’r’,’Parent’,f1);
% Other subplots %
else
figure(fig1)
% Update new info for both scatterplots and overlay them in the first subplot
set(sc1,’XData’,x1,’YData’,y1,’CData’,repmat(sc1.CData(1,:)),’Parent’,f1);
hold on;
scatter(x2,y2,’r’,’Parent’,f1);
% Other subplots %
end

% Plot some other figure
if ~(exist(fig2))
fig2 = figure;
ax = axes(‘Parent’,fig1);
% Plot Figure 2
else
figure(fig2)
% Figure 2 plots and legends using ax
end

end
The problem is, the second scatterplot does not get cleared in the next loop iteration when set(sc1,…) is called. I tried the cla(f1,’reset’) command, but that deletes all the XData, YData variables, which I need to exist in order to update.
I think the "hold on" is creating the persistence issue, but adding "hold off" after the second scatter just clears the entire subfigure including axes.
Is there some other way to accomplish the goal of overlaid scatterplots refreshed in each loop? scatter, overlay figures, axes handles MATLAB Answers — New Questions

​

Tags: matlab

Share this!

Related posts

Generate ST code from a look-up table with CONSTANT attribute
2025-05-22

Generate ST code from a look-up table with CONSTANT attribute

“no healthy upstream” error when trying to access My Account
2025-05-22

“no healthy upstream” error when trying to access My Account

MATLAB Answers is provisionally back?
2025-05-21

MATLAB Answers is provisionally back?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Categories

  • Matlab
  • Microsoft
  • News
  • Other
Application Package Repository Telkom University

Tags

matlab microsoft opensources
Application Package Download License

Application Package Download License

Adobe
Google for Education
IBM
Matlab
Microsoft
Wordpress
Visual Paradigm
Opensource

Sign Up For Newsletters

Be the First to Know. Sign up for newsletter today

Application Package Repository Telkom University

Portal Application Package Repository Telkom University, for internal use only, empower civitas academica in study and research.

Information

  • Telkom University
  • About Us
  • Contact
  • Forum Discussion
  • FAQ
  • Helpdesk Ticket

Contact Us

  • Ask: Any question please read FAQ
  • Mail: helpdesk@telkomuniversity.ac.id
  • Call: +62 823-1994-9941
  • WA: +62 823-1994-9943
  • Site: Gedung Panambulai. Jl. Telekomunikasi

Copyright © Telkom University. All Rights Reserved. ch

  • FAQ
  • Privacy Policy
  • Term

This Application Package for internal Telkom University only (students and employee). Chiers... Dismiss