How to remove border from MATLAB figure
조회 수: 24 (최근 30일)
이전 댓글 표시
I'm trying to compare spectrogram images in a MATLAB image analyzer, but I think the white border is causing them to be overly similar. Because of the number of images I need to process, I'd really like to have it automatically generate and save the image. Here is my current code that I’m using to make and save the spectrogram.
base=filename %The code saves multiple images with the label being the filename and a specific addition to each image
figure(1003)
spectrogram(Xacc,windowx,noverlap,nfft,fs,'yaxis')
ylim([0 5])
colormap(gray(256));
caxis([-160 40])
% title('Spectrogram of X')
s1=base + "SPEC_Acc_X GS";
saveas(gcf,s1,'jpg')
When I run it I get an image like this.
What I want is an image like this, but in order to get it I had to adjust every setting manually in the image editor. Alternately, is there a way to automatically crop saved images? That could also be a solution.
Thanks so much for the help!
댓글 수: 0
답변 (1개)
Star Strider
2024년 9월 10일
It might be easier to do that when you first create the spectrogram.
Try something like this —
Fs = 1000;
L = 10;
t = linspace(0, Fs*L, Fs*L+1).';
s = sum(sin(2*pi*t*(1:75:490)),2)*1E+3;
figure
spectrogram(s,[],[],[],Fs,'yaxis')
colormap(gray)
title('Original')
figure
spectrogram(s,[],[],[],Fs,'yaxis')
colormap(gray)
hf = gcf;
hcb = findobj(hf.Children,'Type','ColorBar');
hcb.Visible = 'off';
Ax = gca;
Ax.Visible = 'off';
title('Edited')
% get(hf)
.
댓글 수: 2
Star Strider
2024년 9월 11일
My pleasure!
I wasn’t certain what you wanted, so I took my best guess. I’m happy to have been able to suggest a solution!
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!