How to deal with this error ??
조회 수: 2 (최근 30일)
이전 댓글 표시
Error using + Matrix dimensions must agree. *Error in (line 77) y= d1w + d2w + aa2;
d1 and d2 are details coefficients at level 1 and 2 respectively. aa2 is the approximate coefficient at level 2
ech is an ecg signal
%wavelet decomposition
[C, L] = wavedec(ech, 2,'haar');
%extraction of approximate and detail coefficients of signal ech
aa2 = appcoef(C, L, 'haar', 2);
dd2 = detcoef(C, L, 2);
dd1= detcoef(C, L, 1);
%Wiener computations
s1=median(abs(d1))/.6745;
g1=((dd1).^2)/((dd1).^2)+((s1).^2);
d1w=repmat(d1(:), 1, size(d1)) .*g1;
s2=median(abs(d2))/.6745;
g2=((dd2).^2)/((dd2).^2)+((s2).^2);
d2w=repmat(d2(:), 1, size(d2)) .*g2;
%reconstruct the signal
subplot(3,2,5);
y= d1w + d2w + aa2;
plot(y,'k');
댓글 수: 2
Walter Roberson
2017년 5월 20일
"ech is an ecg signal"
ecg signals are multiple channel, typically either 5 or 12. The code you are using requires that ech is a vector.
Your d1 is not defined in the code. Did you possibly intend to code dd1 instead of d1 ?
답변 (1개)
Walter Roberson
2017년 5월 21일
You have
d1w=repmat(d1(:), 1, size(d1)) .*g1;
g2=((dd2).^2)/((dd2).^2)+((s2).^2);
d2w=repmat(d2(:), 1, size(d2)) .*g2;
size(d1) is a vector, so your repmat is working as if you had used repmat(d1(:), [1 1 500]) when you wanted repmat(d1(:), [1 500]) I guess. Same problem with your repmat for d2w. (Ah, I just realized that 500 is length(ecg)/2 )
When you get down to
y= d1w + d2w + a2
you run into the fundamental problem that arrays derived from d1 are length(x)/2 on a side, but arrays derived from d2 are length(x)/4 on a side. You will not be able to add them.
댓글 수: 4
Walter Roberson
2017년 5월 21일
You are attempting to add matrices that are inherently differently sizes, one half the size of the other. You need to go back and figure out what you are trying to do there.
참고 항목
카테고리
Help Center 및 File Exchange에서 Discrete Multiresolution Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!