# Error using Plot. Vectors must be the same length

3 views (last 30 days)
John on 23 Nov 2013
Edited: Azzi Abdelmalek on 23 Nov 2013
Hi everyone!I am still new to Matlab. I have encountered an error when trying to plot. Pls tell me the errors I made and let me know which one to change. Thanks!
y=ecg_8(:,2);
A=ecg_8(:,2)-mean(ecg_8(:,2));
fs=1000;
t=0:1/fs:(length(ecg_8)-1)/fs;
B=((4.096+4.096)/4096)/1000;
plot(t*1000,A*B*1000)
y2=fft(A);
L=length(y2);
freq=(0:fs/(L-1):fs);
plot(freq,abs(y2));
axis([0 ,500 ,0, 30000000])
n=(-100:100);
blackw= 0.42+0.5*cos(2*pi*n/101)+0.08*cos(4*pi*n/101);
w1=2*pi*0.025;
w2=2*pi*0.075;
h4=(1./(n*pi)).*(sin(w1*n)-sin(w2*n));
h4(101)=1+(w1-w2)/pi;
h4=h4.*blackw;
h40=20*log10(abs(fft(h4)));
figure(1),subplot(2,1,1),plot(0:10:1000,h40)
axis([-50 1050 -30 10]),title('Step 4 frequency domain')
subplot(2,1,2),plot(h4),
firs4=myFIR(ecg_8,h4);
figure(2), plot(firs4, title('step 4'))
xlabel('time(ms)'),ylabel('voltage(mv)')
Error using plot

Azzi Abdelmalek on 23 Nov 2013
This line is not correct
plot(firs4, title('step 4'))
Replace it by
plot(firs4)
title('step 4'))
##### 2 CommentsShowHide 1 older comment
Azzi Abdelmalek on 23 Nov 2013
function output1 = myFIR1(input1,hn)
output1(1:length (input1),1)=0;
for R =1:length (input1)
CC=length(hn);
if R<length(hn)
CC = R;
end
for C= 1:CC
output1(R)= output1(R)+(input1(R+1-C)*hn(C));
end
end
% Don't use input as a variable, because it's a Matlab function. Save your function then call it as
input1=1:3;
hn=2:10
output1 = myFIR1(input1,hn)