필터 지우기
필터 지우기

Error using Plot. Vectors must be the same length

조회 수: 1 (최근 30일)
John
John 2013년 11월 23일
편집: Azzi Abdelmalek 2013년 11월 23일
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!
load 'ecg_8.dat'
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

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 11월 23일
This line is not correct
plot(firs4, title('step 4'))
Replace it by
plot(firs4)
title('step 4'))
  댓글 수: 2
John
John 2013년 11월 23일
Hi, I am encountering the same error. On top of this I'm creating a FIR Filter implementation. Here is the code I done:
function output = myFIR1(input,hn)
output(1:length (input),1)=0;
for R =(1:length (input))
if R<length(hn)
CC = R;
elseif R>=length(hn)
CC=length(hn);
end
for C= 1:CC %loop for "n times"
output (R)= output(R)+(input(R+1-C)*hn(C));
end
end
end
Azzi Abdelmalek
Azzi Abdelmalek 2013년 11월 23일
편집: Azzi Abdelmalek 2013년 11월 23일
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)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by