필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How can I fix this error?

조회 수: 1 (최근 30일)
Ghazal Hnr
Ghazal Hnr 2017년 3월 12일
마감: MATLAB Answer Bot 2021년 8월 20일
Hello, I wrote this code:
figure(3)
dt = 0.001;
T = 60;
t = [0:dt:T] ;
omega0 = 2 * pi / T;
for k = 1:20
ck = cos (k * omega0 * t); % cosine component
a(k) = 2/T * ( sum (ECG_ac.*ck) * dt);
sk = sin (k * omega0 * t); % sine component
b(k) = 2/T * ( sum (ECG_ac.*sk) * dt);
end
magnitude = sqrt(a.^2 + b.^2);
plot(magnitude)
but i have this error:
Error using .*
Matrix dimensions must agree.
Error in Q2ECG (line 40)
a(k) = 2/T * ( sum (ck.*ECG_ac) * dt);
what's wrong?
Thanks for your help

답변 (2개)

Roger Stafford
Roger Stafford 2017년 3월 12일
Judging by your error message, the two arrays, ck and ECG_ac, have different sizes. That's a no-no.
  댓글 수: 4
Roger Stafford
Roger Stafford 2017년 3월 13일
Just change dt:
dt = linspace(0,T,15000);
Ghazal Hnr
Ghazal Hnr 2017년 3월 13일
I have the same error again!

Walter Roberson
Walter Roberson 2017년 3월 13일
T = 60;
t = linspace(0,T,length(ECG_ac));
dt = t(2)-t(1);
omega0 = 2 * pi / T;
for k = 1:20
ck = cos (k * omega0 * t); % cosine component
a(k) = 2/T * ( sum (ECG_ac.*ck) * dt);
sk = sin (k * omega0 * t); % sine component
b(k) = 2/T * ( sum (ECG_ac.*sk) * dt);
end
magnitude = sqrt(a.^2 + b.^2);
plot(magnitude)

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by