简体   繁体   中英

Help Required With Graph Plotting in MATLAB

I am about to present my work that I have created in MATLAB, but I am having trouble manipulating my data into a presentable form using the plot function.

My code looks like this:

[inputname, pathname] = uigetfile('*.wav', 'Select WAV-file');

thumb1 = inputname;               %# Get filename information
fprintf('\n%s is being turned into a 30s thumbnail...\n', thumb1);
fprintf('Please wait..!\n\n');
%# load the signal
[y, fs, nb] = wavread(thumb1);
y = mean(y,2);                               %# stereo, take avrg of 2 channels

%# Calculate frame energy
fWidth = round(fs*10e-3);                    %# 10ms
numFrames = floor(length(y)/fWidth);
energy = zeros(1,numFrames);
for f=1:numFrames
  energy(f) = sum( y((f-1)*fWidth+1:f*fWidth).^2 );
end

Basically I want to plot the energy of the track over time (in seconds).

plot(energy)

nearly does what I require, but I have an unusual amount of blank space at the end of the track which is not present in the .wav file 替代文字 . This blank space is the main issue that I'm having. Ideally I would like the x axis to be displayed in seconds! Any help would be much appreciated.

edit1:

Using the first suggested method:

替代文字

By default, Matlab uses some heuristic rules to choose the limits of graph scales. You can override them with the xlim and ylim functions (eg xlim([0 length(energy)]) ).

If you want to plot against actual time, you can do something like:

t = (0:length(energy)-1) / fs;  % Timebase in seconds
plot(t, energy);

There's also

axis tight

which sets "tight" limits for the axis. See doc: http://www.mathworks.com/help/techdoc/ref/axis.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM