# MATLAB: Plotting MATRIX?

• Jan 25th 2009, 10:11 AM
synnexster
MATLAB: Plotting MATRIX?
How would I plot Q in this? I keep getting an error.

Code:

```[x,fs,k]=wavread('sound0.wav'); x = x(1:length(x),1); N=length(x); time=[0:1:N-1]*1/fs; dead=zeros(fs,1); x1=[x;dead;dead;dead]; x2=0.7*[dead;x;dead;dead]; x3=(.5)*[dead;dead;x;dead]; x4=(.3)*[dead;dead;dead;x]; q=x1+x2+x3+x4; %sound(q,fs); plot(time,q);```
• Jan 25th 2009, 10:56 AM
Constatine11
Quote:

Originally Posted by synnexster
How would I plot Q in this? I keep getting an error.

Code:

```[x,fs,k]=wavread('sound0.wav'); x = x(1:length(x),1); N=length(x); time=[0:1:N-1]*1/fs;     dead=zeros(fs,1); x1=[x;dead;dead;dead]; x2=0.7*[dead;x;dead;dead]; x3=(.5)*[dead;dead;x;dead]; x4=(.3)*[dead;dead;dead;x];     q=x1+x2+x3+x4; %sound(q,fs); plot(time,q);```

Why are dead and x of the same length?

Also if you want help finding the error in future tell us what the error message is, and at what point in the script that it occurs.

.
• Jan 25th 2009, 11:10 AM
synnexster
It happens at the plot(time,q); line.

Here is the error:

??? Error using ==> plot
Vectors must be the same lengths.

dead adds 1 second of silence, and i've added echos: x1,x2,x3,x4. I just want to plot it.
• Jan 25th 2009, 12:21 PM
Constatine11
Quote:

Originally Posted by synnexster
It happens at the plot(time,q); line.

Here is the error:

??? Error using ==> plot
Vectors must be the same lengths.

dead adds 1 second of silence, and i've added echos: x1,x2,x3,x4. I just want to plot it.

You have not extended time in the same way you have extended q.

Learn to use the debugger and single step through the script querying the size of the arrays as you go.

.