Error using ==> times Matrix dimensions must agree.

When I am executing this program, I got the error message
??? Error using ==>times Matrix dimensions must agree.
all i need to have is a signal that i will plot after multiplying the h vector and x input signal .
even with the same length , i couldn't find the problem
%generation de la reponse impultionnelle
h=[ zeros(1 ,480) -436 -829 -2797 -4208 -17968 -11215 46150 34480 -10427 9049 -1309 -6320 390 -8191 -1751 -6051 -3796 -4055 -3948 -2557 -3372 -1808 -2259 -1300 -1098 -618 -340 -61 323 419 745 716 946 880 1014 976 1033 1091 1053 1042 794 831 899 716 390 313 304 304 73 -119 -109 -176 -359 -407 -512 -580 -704 -618 -685 -791 -772 -820 -839 -724 zeros(1 , 480)]
figure, plot(h)
axis([ 0 1024 -30000 50000]);
xlabel('amp');
ylabel('pnt');
title('reponse impulsionnelle ');
set(gcf, 'Color', [1 1 1])
%creation du signal far-end
[x,fs]=wavread('Alarm01.wav');
t=linspace(0,length(x)/fs,length(x)); % creation du vecteur temps
plot(t,x)
figure, plot(h)
Nfft=1024; %longueur du vecteur frequence
f=linspace(0,fs,Nfft);
G=abs(fft(x,Nfft));
figure ; plot(f(1:Nfft/2),G(1:Nfft/2),'g')
y=h'.*G.
plot(y)

 Akzeptierte Antwort

Roger Stafford
Roger Stafford am 7 Apr. 2016

0 Stimmen

Your vector t is a row vector, that is, presumably 1 by 1024 in size. If there is no complaint in plot(t,x), then x must also be 1 by 1024, which in turn means that G is 1 by 1024. However the vector h' is 1024 by 1, and that would produce an error in the multiplication y = h'.*G . You should insert size(h') and size(G) just before that multiplication to verify this.

4 Kommentare

thnks,actualy i used the G vector that is 1 by 1024 , i mean same as h .and the for loop to fixe the problem so that i store all the values from 1 to 1024 of my new vector befor the plot
y=0;
for i=1:Nfft
Y(i)=h(i)'.*G(i)
end
plot(Y);
Roger Stafford
Roger Stafford am 8 Apr. 2016
Bearbeitet: Roger Stafford am 8 Apr. 2016
You can accomplish the same thing with:
Y = h.*G;
since this way both arrays are 1 by 1024.
amira kadd
amira kadd am 8 Apr. 2016
ah ok thanks , do you mean even without the transposed vector of h it works ?
Your h, as you have written it here, is a row vector 1-by-1024 in size. It is only h.*G that works, and h'.*G does NOT work, since G is also a row vector of the same size as h.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by