Azzera filtri
Azzera filtri

2 different markers in loop, show both when applicable

1 visualizzazione (ultimi 30 giorni)
I have a loop processing the VEI index of volcanoes for various years.
Say in some years, VEI4lat is [0]. The var exists, but the values are 0. The map won't plot anything and the legend disappears. The volcsymbol2 doesn't show for all my plots now, and the legend also doesn't show the volcsymbol2. My map plots and legend only show volcsymbol...
% marker for VEI <= 3
volcsymbol = plotm(VEI3lat,VEI3long,'^','markersize',8,'markerfacecolor','r', ...
'markeredgecolor','k','linewidth',0.5);
if isequal(VEI4lat,[0]) == 0,
elseif isequal(VEI4lat,[0]) == 1
% Volcano marker for VEI >= 4
volcsymbol2 = plotm(VEI4lat,VEI4long,'^','markersize',8,'markerfacecolor','k', ...
'markeredgecolor','k','linewidth',0.5);
end
% Creating legend on map
if isequal(VEI4lat,[0]) == 1
legend([volcsymbol,volcsymbol2],{'VEI <= 3','VEI >= 4'},'Location','Southeast')
elseif isequal(VEI4lat,[0]) == 0,
legend([volcsymbol],{'VEI <= 3'},'Location','Southeast')
end
  3 Commenti
Madlab
Madlab il 5 Set 2018
Sorry, will edit it now as Im using a phone
dpb
dpb il 5 Set 2018
I finished it for you given the above limitation will grant dispensation... :)

Accedi per commentare.

Risposta accettata

dpb
dpb il 5 Set 2018
if isequal(VEI4lat,[0]) == 0,
is equivalent to
if VEI4lat~=0
and the block is empty so nothing ever happens for any case except zero.
It looks like it should plot just fine for the zero case; are the plot limits such that they include zero; that would be a likely reason don't see data on a plot that think should be there.
The above could be written much succinctly as
if VEI4lat==0
% Volcano marker for VEI >= 4
volcsymbol2 = plotm(VEI4lat,VEI4long,'^','markersize',8,'markerfacecolor','k', ...
'markeredgecolor','k','linewidth',0.5);
legend([volcsymbol,volcsymbol2],{'VEI <= 3','VEI >= 4'},'Location','Southeast')
else
legend([volcsymbol],{'VEI <= 3'},'Location','Southeast')
end
since there's nothing in the ~= case, it's superfluous for plotting but the subsequent if block for legend may as well be folded in.
BUT, be aware that there can only be one legend and so whichever is the one that is last called will be what is left, in general one should save the handles to the line objects from plot and assign labels to the specific handles desired for the legend.
  2 Commenti
Madlab
Madlab il 6 Set 2018
dpb, Thank you very much for your comments. They were really very helpful. I managed to use something similar to what you suggested, except that I edited 'VEI4lat==0' to sum(VEI4lat)=0, as the former did not work.
dpb
dpb il 6 Set 2018
Ah! We can't tell from your original posting what what VEI4lat, etc., are...if they are vectors then use
if all(VEI4lat)==0
I had presumed they were going to be single values at that point.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by