MATLAB: How to find a non affected rank in a vector column

find empty variable ?MATLAB

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

Best Answer

  • Probably for such a case as written
    for j=1:4
    will solve the problem; if you're out to optimize,
    set(h_leg([1 2 4]),'fontsize',12)
    altho the subscript vector should be coded dynamically instead of hardcoded (as should the loop be over 1:numel(h_leg) instead of 1:4)
    What is the type of h_leg()?