Sumedha Vangury
Sumedha Vangury

Reputation: 61

matlab error matrix dimension must agree

i am attempting to debug a part of the code but getting this error:

??? Error using ==> plus

Matrix dimensions must agree.

Error in ==> dwtembed at 48 cH1=cH1+k*pn_sequence_h;

This is the code segment:

for kk=1:length(message_vector)  
pn_sequence_h=round(2*(rand(Mc/2,Nc/2)-0.5)); 
pn_sequence_v=round(2*(rand(Mc/2,Nc/2)-0.5)); 
if (message(kk) == 0) 
    cH1=cH1+k*pn_sequence_h; 
    cV1=cV1+k*pn_sequence_v; 
end 
end 

These are the values for the variables:

kk 18096  
message_vector <150096x1 double>  
pn_sequence_h <118x116 double>  
Mc 236  
Nc 232  
pn_sequence_v <118x116 double>  
cH1 <118x116x3 double>  
cV1 <118x116x3 double>  
k   2

Can you please help me out with the information provided.

Upvotes: 0

Views: 220

Answers (1)

Shai
Shai

Reputation: 114826

You have mismatch dimensions. You are trying to add CH1 of size 118x116x3 (a 3D array) with on_sequence_h which is 118x116 (a 2D matrix). This operation is not defined

You may use bsxfun:

cH1 = bsxfun( @plus, cH1, k*pn_sequence_h ); 

Upvotes: 1

Related Questions