Saving High Quality graphs within loop

2 ビュー (過去 30 日間)
federico nutarelli
federico nutarelli 2021 年 7 月 20 日
回答済み: Bjorn Gustavsson 2021 年 7 月 20 日
Hii all,
I am using a package called borders in matlab to make colored maps. The problem is that the countries have to be colored one by one within a for loop. Now my aim is to save the depicted world in high resolution. My code looks as follows:
bord = borders('countries','r');
borders('countries','facecolor',[0.85,0.85,0.85])
axis tight
%W
for k=1:size(genepy_W_W_pred,1)
if genepy_W_W_pred.dummy_W(k)==1 %se è W_pred
borders(cell2mat(genepy_W_W_pred.ctry_W_W_pred(k)),'facecolor',genepy_W_W_pred.color(k,:))
end
end
exportgraphics(bord,'genepy_hs4_W_HQ.jpg','Resolution',500)
and it is basically creating a map of the world with red boundaries and coloring the countries one by one according to genepy_W_W_pred. I was trying to use exportgraphics(bord,'genepy_hs4_W_HQ.jpg','Resolution',500) but it raisses an handle issue.
Is there a way to name the figure appearing on the panel and save it in high resolution?
Thank you

回答 (1 件)

Bjorn Gustavsson
Bjorn Gustavsson 2021 年 7 月 20 日
The first input-argument to exportgraphics is supposed to be a handle to any type of axes. The handle you send in might very well be lost in the plotting function-calls you perform after you generate it. Maybe you get the proper handle to the current axes if you use an output-argument to the borders call in the loop:
bord = borders('countries','r');
borders('countries','facecolor',[0.85,0.85,0.85])
axis tight
%W
for k=1:size(genepy_W_W_pred,1)
if genepy_W_W_pred.dummy_W(k)==1 %se è W_pred
bord = borders(cell2mat(genepy_W_W_pred.ctry_W_W_pred(k)),...
'facecolor',genepy_W_W_pred.color(k,:));
end
end
exportgraphics(bord,'genepy_hs4_W_HQ.jpg','Resolution',500)
What are the benefits of using exportgraphics instead of print?
HTH

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by