How to deal with this error ??
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 20 Mai 2017
"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 ?
Réponses (1)
Walter Roberson
le 21 Mai 2017
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 commentaires
Walter Roberson
le 21 Mai 2017
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.
Voir également
Catégories
En savoir plus sur Discrete Multiresolution Analysis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!