Reputation: 125
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:
Upvotes: 0
Views: 348
Reputation: 25160
There's also
axis tight
which sets "tight" limits for the axis. See doc: http://www.mathworks.com/help/techdoc/ref/axis.html
Upvotes: 1
Reputation: 272687
By default, Matlab uses some heuristic rules to choose the limits of graph scales. You can override them with the xlim
and ylim
functions (e.g. 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);
Upvotes: 1