Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

plot

Asked by Padma on 1 Nov 2011
 [FileName,PathName] = uigetfile('padma_orignl.wav');
>> PathOriginal=sprintf('%s%s',PathName,FileName);
>> [xt,fs]=wavread(PathOriginal);
>> [FileName,PathName] = uigetfile('padma_delay.wav');
>> PathOriginal1=sprintf('%s%s',PathName,FileName);
>> [yt,fs]=wavread(PathOriginal1);
>> t=0:1/30897:1;
>> plot(t,xt,t,yt)
Error using plot
Vectors must be the same lengths.

When i have recorded two sample wav files, one with no delay and other with delay, obviously there would be some difference in length. Could you please tell me how i could overcome this error?

Thanks in advance Padma

0 Comments

Padma

Tags

Products

No products are associated with this question.

1 Answer

Answer by Honglei Chen on 1 Nov 2011

There are several things you can do, the simplest is probably

plot(t,xt(1:length(t)),t,yt(1:length(t)))

This assumes that your data is at least as long as t, otherwise you'll have to truncate your t.

If you want to go a little further, you can do

t1 = 0:1/30897:length(xt);
t2 = 0:1/30897:length(yt);
plot(t1,xt,t2,yt)

HTH

2 Comments

Honglei Chen on 1 Nov 2011

I just fix a typo in my original post, I typed 20897 for t2 instead of 30897. You mention that your computer freezes and that might be because your xt and yt are too long. You could try something simple to make sure it works first, e.g.,

N = 1000; plot(t1(1:N),xt(1:N),t2(1:N),yt(1:N))

Honglei Chen on 1 Nov 2011

Hi Padma, Please add your comment here so other people can contribute too. To get comparable magnitude, you can try to normalize them, e.g.,

N = 1000; plot(t1(1:N),xt(1:N)/max(abs(xt)),t2(1:N),yt(1:N)/max(abs(yt)))

I'm not sure why your computer freezes when you set N = 10000, it is not a lot of data to plot. Maybe you can only create t for the points you with to plot? e.g.,

N = 10000; t = (0:N-1)/30897; plot(t,xt(1:N),t,yt(1:N));

Honglei Chen

Contact us