MATLAB Answers

How can I change the colorbar limits/scale of a spectrogram?

조회 수: 7(최근 30일)
Sebastian Vazquez
Sebastian Vazquez 2021년 7월 19일
댓글: Sebastian Vazquez 2021년 7월 19일
Hello, I would like to change the limits of the colorbar for a spectrogram so that all my plots have an identical scale. Here is the code I am using:
clc; close all; clear variables;
trial1 = 'No_water_charge.wav';
[y1,Fs1] = audioread(trial1); %Reading the wav file
t1 = 0:1.00002/Fs1:length(y1)/Fs1; %Calculating the time
newFs1 = 3000; %New sampling frequency
[P1,Q1] = rat(newFs1/Fs1); %Assigning ratio values to new Fs
newy1 = resample(y1,P1,Q1); %Resampling the data
newt1 = 0:1.000002/newFs1:length(newy1)/newFs1; %Creating a new time
figure
spectrogram(newy1,256,250,[],newFs1,'yaxis','psd');%Generating the spectrogram
title('No water charge')
h1 = gca;
h1.XTickLabel = string(h1.XTick*60);
xlabel('Time (s)');
trial2 = 'No_water_discharge.wav';
[y2,Fs2] = audioread(trial2);
t2 = 0:1.00002/Fs2:length(y2)/Fs2;
newFs2 = 3000;
[P2,Q2] = rat(newFs2/Fs2);
newy2 = resample(y2,P2,Q2);
newt2 = 0:1.000002/newFs2:length(newy2)/newFs2;
figure
spectrogram(newy2,256,250,[],newFs2,'yaxis','psd')
title('No water discharge')
h2 = gca;
h2.XTickLabel = string(h2.XTick*60);
xlabel('Time (s)');
This code produces the following plots:
If possible, I would like their colorbar scales to be the same so instead of one maxing out at 80 and the other at 90, I would like them both to be at 80 if possible. Thank you for your time.

추가 답변(0개)

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by