How to remove border from MATLAB figure
28 ビュー (過去 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!