Effacer les filtres
Effacer les filtres

2 different markers in loop, show both when applicable

1 vue (au cours des 30 derniers jours)
Madlab
Madlab le 5 Sep 2018
Commenté : dpb le 6 Sep 2018
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 commentaires
Madlab
Madlab le 5 Sep 2018
Sorry, will edit it now as Im using a phone
dpb
dpb le 5 Sep 2018
I finished it for you given the above limitation will grant dispensation... :)

Connectez-vous pour commenter.

Réponse acceptée

dpb
dpb le 5 Sep 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 commentaires
Madlab
Madlab le 6 Sep 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 le 6 Sep 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by