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

3 次查看(过去 30 天)
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

回答(2 个)

Jan
Jan 2021-9-7
编辑:Jan 2021-9-7
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 个评论
Jan
Jan 2021-9-8
编辑:Jan 2021-9-8
legend is one of the commands with the most changes between the Matlab versions. Some changes are useful, many are not compatible. What do you want to do with the line handles? See:
In HG1 the handles of the legend's line objects have been replied as further output arguments. I've used them to attach callbacks to let the user move a line to the top by clicking in the legend, if the line is hidden behind others. In another case I've removed markers from the legend, because they are useful in a diagram only.
I have the need to write code, which runs under R6.5, 2009a and 2018b. I found many workarounds, e.g. creating my own graphic handles as pseudo-object using structs, and created an own string library for the useful commands: contains, startsWith etc. But legend is a severe problem, because the feature are changing too rapidly and there is no chance to get a stable set of methods for such tweaks as mentioned above.
My solution is not to use the legend command for productive work.
I'm very happy that only unique,union,intersect,setdiff and strncmp have a comparably high variability between the Matlab versions.
Sajid Afaque
Sajid Afaque 2021-10-25
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

请先登录,再进行评论。


Steven Lord
Steven Lord 2021-10-25
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.

类别

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

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by