필터 지우기
필터 지우기

How to save histogram as a png file with the axis values (as it displays in imhist() function ) inside a loop?

조회 수: 29 (최근 30일)
Hello, I am new to matlab, I want to save the histogram as it shows in the imhist function. but when I save it, it only saves the spikes (bars), but, does not save the entire histogram (x and y axis are not saved with with the spikes). also I want to create a histogram in each irritation of the loop and save them with different name, (as Hist11, Hist12, hist21,hist22.....etc) the name will contain the row number and column number. Here is the code I have tried already. Thank You.
imwrite(imhist(temp),'F:\499\Histogram\h1.png');
saveas(im1,sprintf('HIS%d.png',i));

채택된 답변

KSSV
KSSV 2018년 5월 31일
편집: KSSV 2018년 5월 31일
Try:
imhist(temp);
saveas(gcf,sprintf('HIS%d.png',i));
  댓글 수: 4
Sheikh Faishal Basher
Sheikh Faishal Basher 2018년 5월 31일
@Stephen Cobeldick Here is the full error message. Thank you.
Error using name (line 102)
Cannot create output file '.\HIS1.png'.
Error in print (line 85)
pj = name( pj );
Error in saveas (line 168)
print( h, name, ['-d' dev{i}] )
Error in Histogram (line 66)
saveas(gcf,sprintf('HIS%d.png',i));

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

추가 답변 (1개)

Aditya Salveru
Aditya Salveru 2018년 5월 31일
Hi,
You can save the entire histogram using as it shows in the imhist functions using the below code snippet.
saveas(gcf,sprintf('HIS%d.png',i))
Run this snippet in the loop to create multiple histograms and save them.
I am giving an example code with loop to create and save multiple histograms.
x=[1 2 2 4 4 5 5 5];
while(length(x)<15)
imhist(x)
saveas(gcf,sprintf('HIS%d.png',length(x)))
x=[x length(x)];
end
Thank you.
Aditya Salveru.
  댓글 수: 1
Sheikh Faishal Basher
Sheikh Faishal Basher 2018년 5월 31일
편집: Sheikh Faishal Basher 2018년 5월 31일
Thank you for your answer. But the code shows error and is not working.
Error using name (line 102)
Cannot create output file '.\HIS1.png'.
Error in print (line 85)
pj = name( pj );
Error in saveas (line 168)
print( h, name, ['-d' dev{i}] )
Error in Histogram (line 66)
saveas(gcf,sprintf('HIS%d.png',i));

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

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by