Saving a plot as png 224*224*3 image

Hi,
I have generated a plot in Matlab as shown in figure.When i save it using 'saveas(gcf,'im1.png')' , it is saved as a 656*875*3 png image.I want to save it as 224*224*3 png image without the axis titles,labelling and colorbar.i.e.only the actual plot.Can anyone kindly guide on it?
guide about
Thanks

2 Comments

Can you share plot details?
Its a spectrogram with frequency on y axis and time on x axis

Sign in to comment.

Answers (1)

Rik
Rik on 17 Feb 2021
You can do three things:
  1. Don't create your image as a plot, but as an image.
  2. Crop the image down to the location of your axes object.
  3. Use export_fig.

14 Comments

Can you kindly guide further about option 1?
That depends on how you created this plot. You can probably round your data to integer and use ind2rgb to convert to an RGB image. If you attach example data and your code, we might be able to give an explicit example.
load('data.mat');
x = sum(AA/max(max(abs(AA)))); %normalizing bw 0 and 1 and summing across rows
a=size(x);
for k=4960:4960:a(2)
x1=x(k-4959:k);
figure();
c=jet(256);colormap(c);
spectrogram(x1,hanning(512),487,1024,12.4e3,'centered','yaxis','MinThreshold',-60);
end
Your data is not attached and if hanning is a function, it no longer exists (although there is a hann function).
I don't have the signal processing toolbox, so I will need to expirement with the Run feature in this forum.
I am unable to attach data as max limit is 5MB for attachments.
Can you reduce the size of the variables? Is all data really necessary? The image will look differently, but I should still be able to reproduce a similar image.
Hi,
Attached is the data..loop will not be necessary as data is less now.
What code should I be using?
load('data.mat');
x = sum(AA/max(max(abs(AA)))); %normalizing bw 0 and 1 and summing across rows
a=size(x);
for k=4960:4960:a(2)
x1=x(k-4959:k);
figure();
c=jet(256);colormap(c);
spectrogram(x1,hanning(512),487,1024,12.4e3,'centered','yaxis','MinThreshold',-60);
end
Your mat file contains the variable data, which is not even used by the code. How am I supposed to help you like this?
Check that your code doesn't use any variables appart from those in the mat file.
Put your mat file in a separate folder, call clearvars and then run your code. If it doesn't run for you, it will not run for me either.
And please use the S=load('data.mat') syntax. That will show you immediately where variables are coming from. If it isn't followed by AA=S.AA; I don't even have to download your mat file before telling you that you fix your example.
Also, use the formatting tools when posting.
Hi Rik,
Sorry for replying late. Actually, i uploaded the data file after modification(due to attachment size limitation) but forgot to change code accordingly. I have corrected the code as follow. Now it will work with the mat file. Make sure to put the mat file in the Matlab path.
load('data.mat');
x = sum(data/max(max(abs(data)))); %normalizing bw 0 and 1 and summing across rows
figure();
c=jet(256);colormap(c);
spectrogram(x,hanning(512),487,1024,12.4e3,'centered','yaxis','MinThreshold',-60);
Please use the S=load('data.mat') syntax.
S=load('data.mat');
x = sum(S.data/max(max(abs(S.data)))); %normalizing bw 0 and 1 and summing across rows
figure();
c=jet(256);colormap(c);
spectrogram(x,hanning(512),487,1024,12.4e3,'centered','yaxis','MinThreshold',-50);
Hi @Rik,
Waiting for your response.
thanks

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Products

Release

R2018a

Asked:

ali
on 17 Feb 2021

Commented:

ali
on 24 Jun 2021

Community Treasure Hunt

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

Start Hunting!