how to find a non affected rank in a vector column
Mostra commenti meno recenti
Dear matlab users,
in order to make lghter my script I treat the format of the legend of several plots in a dedicated zone of my script
figure(1); plot(x,y); h_leg(1) = legend('plot1')
...
figure(2); plot(x,y); h_leg(2) = legend('plot2')
...
figure(4); plot(x,y); h_leg(4) = legend('plot4')
...
%% overall treatment of the various legends
for j=1:4; set(h_leg(j),fontsize,12); end
here, the issue is that h_leg(3) does not exist and the last loop will fail in dealing with h_leg.
is there any mean to check that this class of object has some rank left undefined? A kind of isempty(h_leg(3)) for example
Thanks for your help
Cheers
Risposta accettata
Più risposte (2)
Walter Roberson
il 30 Apr 2019
You can use isvalid() or ishghandle()
set(h_leg(isvalid(h_leg(1:4))), 'fontsize', 12);
No loop needed. If h_leg is maximum size 4 then leave out the (1:4)
4 Commenti
Frederic Cleva
il 2 Mag 2019
Walter Roberson
il 2 Mag 2019
In the case where you always want to deal with all of h_leg then
set(h_leg(ishghandle(h_leg)), 'fontsize', 12)
Walter Roberson
il 2 Mag 2019
Frederic Cleva comments to me:
This makes the job too (ishghandle) !! Thanks
dpb
il 2 Mag 2019
Indeed...either it or isgraphics turns out to return False for the uninitialized graphics object array elements -- I hadn't found either; the doc links are quite remiss at least on R2017b that is presently latest installed here (R2018b having mysteriously disappeared and not having had time to dig into why/reinstalling)...
Frederic Cleva
il 2 Mag 2019
0 voti
Categorie
Scopri di più su Creating, Deleting, and Querying Graphics Objects in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!