简体   繁体   English

MATLAB中图形绘图所需的帮助

[英]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. 我将要介绍我在MATLAB中创建的工作,但是在使用plot函数将数据处理为可呈现的形式时遇到了麻烦。

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 几乎可以满足我的要求,但是在曲目的末尾我有非常少的空白空间,.wav文件中没有 替代文字 . This blank space is the main issue that I'm having. 这个空白是我遇到的主要问题。 Ideally I would like the x axis to be displayed in seconds! 理想情况下,我希望以秒为单位显示x轴! Any help would be much appreciated. 任何帮助将非常感激。

edit1: EDIT1:

Using the first suggested method: 使用第一个建议的方法:

替代文字

By default, Matlab uses some heuristic rules to choose the limits of graph scales. 默认情况下,Matlab使用一些启发式规则来选择图形比例的极限。 You can override them with the xlim and ylim functions (eg xlim([0 length(energy)]) ). 您可以使用xlimylim函数覆盖它们(例如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 参见文档: http : //www.mathworks.com/help/techdoc/ref/axis.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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