Saving High Quality graphs within loop

2 Ansichten (letzte 30 Tage)
federico nutarelli
federico nutarelli am 20 Jul. 2021
Beantwortet: Bjorn Gustavsson am 20 Jul. 2021
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

Antworten (1)

Bjorn Gustavsson
Bjorn Gustavsson am 20 Jul. 2021
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

Kategorien

Mehr zu Colormaps finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by