switching from 2013b VERSION TO 2020. Accessing figure handle from plot command

3 views (last 30 days)
Sajid Afaque
Sajid Afaque on 7 Sep 2021
Answered: Steven Lord on 25 Oct 2021
hello all ,
I just switched to 2020 version from 2013b.
when i was checking where 2013 scripts are compatible with 2020, i found that
ep_hdl=plot(0,0,'Visible','off','Color','k');
above code gave me figure handle in 2013b, but not in 2020.
what should i do to get results same as 2013b version so that rest of my code stays intact.
Any help would be helpful.
Thanks in Advance

Answers (2)

Jan
Jan on 7 Sep 2021
Edited: Jan on 7 Sep 2021
No, this did not reply a figure handle in R2013b:
ep_hdl=plot(0,0,'Visible','off','Color','k');
The plot command replied a line handle and it still does in R2020.
With the HG1 interface of R2013b the line handle was a double as all GUI handles. With HG2 the handles are specific types.
If this line handle is used as handle to this line only and the code does not assume, that it a double, the existing code should run without changes. So please post the part of the code, which is failing.
  3 Comments
Sajid Afaque
Sajid Afaque on 25 Oct 2021
Hey Jan,
i will try to explain my problem in detail ,i.e. what used to happen in 2013b version
Imagine i have a figure with six line handles ,with all line handles stored in phdl_bc
Apart from this i created an extra line handle named ep_hdl and used it 3 times
ep_hdl=plot(1,1,'Visible','off','Color','k');
now i was using these handles in legend command
hleg2=legend([ep_hdl,ep_hdl,ep_hdl,phdl_bc], leg_str);
here my leg_str was
(attached)
and the legend displayed was as below
the resultant hleg2 was a handle
this hleg2 was used further to make changes to the legend
nr_headdescr=6;
leg_line=findobj(hleg2,'type','Line');
for i=1:length(leg_line)
leg_tag=get (leg_line(i),'Tag');
if isempty (regexp(ref_total,leg_tag)) || ~isempty(leg_tag) || strcmp(leg_tag,borderstyle)
set (leg_line(i),'LineStyle', 'none')
elseif isempty(leg_tag) && i<length(leg_line)-nr_headdescr
set (leg_line(i),'Marker', '.')
set (leg_line(i),'MarkerSize', 20)
end
end
The resultant legend now looked like this
----------------------------------------Now same code in 2020b version----------------------------------------------------
now my phdl_bc as u mentioned in HG2 interface looks like
and similarly ep_hdl
and now when i use legend command as previously i get
hleg2=legend([ep_hdl,ep_hdl,ep_hdl,phdl_bc], leg_str);
notice the missing text in first two lines of legend and also third line.(1st Issue)
similarly now hleg2 which is to be used later looks like
the leg_str was same as enclosed.
also 2nd issue is now i am not able to process the following block of code as earlier
nr_headdescr=6;
leg_line=findobj(hleg2,'type','Line');
for i=1:length(leg_line)
leg_tag=get (leg_line(i),'Tag');
if isempty (regexp(ref_total,leg_tag)) || ~isempty(leg_tag) || strcmp(leg_tag,borderstyle)
set (leg_line(i),'LineStyle', 'none')
elseif isempty(leg_tag) && i<length(leg_line)-nr_headdescr
set (leg_line(i),'Marker', '.')
set (leg_line(i),'MarkerSize', 20)
end
end
this is because the second line of above code i.e. leg_line is now empty, its not able to find any line object
this is my problem, i have tried to describe it to maximum extent. Any help would be higly appreciated .
Thanks in Advance

Sign in to comment.


Steven Lord
Steven Lord on 25 Oct 2021
Prior to the major graphics changes in release R2014b legend created an axes. As of release R2014b it now creates a legend object instead. See pages 1-29 and 1-30 in this PDF documentation for more information.

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!