フィルターのクリア

2 different markers in loop, show both when applicable

1 回表示 (過去 30 日間)
Madlab
Madlab 2018 年 9 月 5 日
コメント済み: dpb 2018 年 9 月 6 日
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 件のコメント
Madlab
Madlab 2018 年 9 月 5 日
Sorry, will edit it now as Im using a phone
dpb
dpb 2018 年 9 月 5 日
I finished it for you given the above limitation will grant dispensation... :)

サインインしてコメントする。

採用された回答

dpb
dpb 2018 年 9 月 5 日
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 件のコメント
Madlab
Madlab 2018 年 9 月 6 日
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 2018 年 9 月 6 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by