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 CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by