MATLAB Answers

Could anyone help me how to save the bar graph in png format.

조회 수: 1(최근 30일)
jaah navi
jaah navi 2021년 7월 29일
댓글: jaah navi 2021년 7월 29일
how to save the bar graph generated using
in png while the command executes.

채택된 답변

DGM 2021년 7월 29일
편집: DGM 2021년 7월 29일
I'm not sure what you mean by "while the command executes", but...
An example:
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12];
  댓글 수: 4
jaah navi
jaah navi 2021년 7월 29일
thanks for your reply.

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Walter Roberson
Walter Roberson 2021년 7월 29일
%applyhatch is a File Exchange Contribution. We need to install it to
%generate the graphics to demonstrate the save techniques
tn = tempname();
hatch_zip_file = '';
hz = tn + ".zip";
urlwrite(hatch_zip_file, hz);
cleanme = onCleanup(@() delete(hz));
hzf = tn + "_folder";
unzip(hz, hzf);
cleanme2 = onCleanup(@() delete(fullfile(hzf, '*')))
cleanme2 =
onCleanup with properties: task: @()delete(fullfile(hzf,'*'))
fig = figure('name', 'original figure')
fig =
Figure (1: original figure) with properties: Number: 1 Name: 'original figure' Color: [1 1 1] Position: [671 661 577 433] Units: 'pixels' Show all properties
fig2 = setdiff(get(0,'children'), fig)
fig2 =
Figure (2) with properties: Number: 2 Name: '' Color: [1 1 1] Position: [671 661 577 434] Units: 'pixels' Show all properties
satn = tn+"_saveas.png";
ptn = tn+"_print.png";
extn = tn+"_exportgraphics.png";
saveas(fig2, satn)
print(fig2, ptn)
exportgraphics(fig2, extn)
folder = fileparts(tn);
dir(fullfile(folder, '*.png'))
tpb156b592_d79a_4c5e_a88b_668e40e767eb_exportgraphics.png tpb156b592_d79a_4c5e_a88b_668e40e767eb_saveas.png tpb156b592_d79a_4c5e_a88b_668e40e767eb_print.png
You can see that all three png files were created.



Community Treasure Hunt

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

Start Hunting!

Translated by