how to concatenation matrices

I tried to execute this which is part of a program i got this error message on the Q1 line(2nd line):
??? Error using ==> vertcat
CAT arguments dimensions are not consistent.Please any hint on what to do to correct it?
P1 =[P111 P112; P121 P122];
Q1=[Q111 Q112; Q121 Q122];
V=[V11 V12 ; V21 V22];
Q2=[Q211 Q212 ; Q221 Q222];
P2 = [P211 P212; P221 P222];
W = (P1*Q1*V*Q2*P2);

8 commentaires

Andrew Newell
Andrew Newell le 9 Jan 2015
Are the arguments like P111 all scalars?
dpb
dpb le 9 Jan 2015
Clearly not; otherwise there would be no size mismatch.
And when OP gets taht sorted out, then undoubtedly there will be a needed "dot" operator on the last line.
Amos
Amos le 9 Jan 2015
Segun, in order to see what is going on, we need you to add the part of your code where Q111, Q112, Q121 and Q122 are defined, or, alternatively, check the dimension of these sub matrices by the command size(Q111) and so on.
segun
segun le 11 Jan 2015
It is a multiplication of two by two matrices that consists of complex numbers and integers.
Image Analyst
Image Analyst le 11 Jan 2015
Did you see my answer about learning how to use the "whos" command and how to use the debugger??? Clearly everything is not 2-by-2 or it wouldn't give that error. And since you won't give us the complete code, like how the P111 etc. are created, you're on your own.
segun
segun le 13 Jan 2015
Modifié(e) : segun le 13 Jan 2015
Thanks for your care, i have been trying to resolve this for a long time with no success.The whole code is a little bit lengthy but here it is as requested: for f =[1 2 3 4 5 6 7 8 9 10]; x1=0.2; x2 = 0.8; w=2*pi*f; a = 95; b = 105; Zcb = (a + (b-a)*rand(1,100)); C1 = 0 + 2.5369.*randn(100,1); for i = 1:length(Zcb); for C1=1:length(C1); Zok = (1 + (0.055*(1-1i))/sqrt(f)); Zcbk = abs(Zcb*Zok); Zg = 100; Zl= 100; Zcu=1/1i*w*C1; u = ((494)+(36/f))*1.0e-9; Vpk = 100/u ; Attk = 1.05*(1.9108*sqrt(f)+0.022*f+0.2/sqrt(f))+4*0.04*sqrt(f); Qk = ((Attk)*(0.01))/(8.68588963807); Bk = (2*pi*f*1.0e6)/(Vpk); Yk =(Qk + 1i*Bk); M = (exp(Yk*x1) + exp(-Yk*x1))/2; N = (exp(Yk*x1) - exp(-Yk*x1))/2; Q = (exp(Yk*x2) + exp(-Yk*x2))/2; R = (exp(Yk*x2) - exp(-Yk*x2))/2; S = M/N; U = Q/R; P111 = M ; P112 = Zcbk*N; P121 = N./Zcbk; P122 = M; P1 =[P111 P112 ; P121 P122]; Q111 = 1; Q112 = 0; Q121 = 1/Zcbk.*U; Q122 = 1; Q1=[Q111 Q112 ; Q121 Q122]; V11 = 1 ; V12 = Zcu; V21 = 0; V22 = 1; V=[V11 V12 ; V21 V22]; Q211 = 1; Q212 = 0; Q221 = 1/Zcbk*S; Q222 = 1; Q2=[Q211 Q212 ; Q221 Q222]; P211 = Q ; P212 = Zcbk*R; P221 = R/Zcbk; P222 = Q; P2 = [P211 P212; P221 P222]; W1 = P1*Q1*V*Q2*P2; W1 = [W1(1,1) W1(1,2) ; W1(2,1) W1(2,2)]; B1 = Zl*(Zl*W1(1,1) + W1(1,2) + Zg*Zl*W1(2,1) + Zg*W1(2,2)); I1=(Zg + Zl); I= I+I1; end end A = (20*log10(abs(1/Zl*I))); disp(A); end
Image Analyst
Image Analyst le 13 Jan 2015
It's not the whole code. Why do you make it difficult for us to help you? Please read this. The code is not formatted. Once I fixed that, there was an extra end in there. Once I fixed that, it said f was not define (a different error than you're asking about). After that I gave up.
segun
segun le 13 Jan 2015
Modifié(e) : segun le 13 Jan 2015
Sorry for the trouble , i have checked and corrected it .Thanks as i await your help.

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 10 Jan 2015

0 votes

You are kidding me. Don't tell me you've been working on this since last July and still don't have a solution that works yet. http://www.mathworks.com/matlabcentral/answers/141425-syntax-to-multiply-two-by-two-matrices-with-zeros-in-it-with-numbers
Why not just learn how to debug http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/, or, worst case, just put a bunch of "whos" commands in there to find out what the rows and columns of all your arrays are. If you stitch together horizontally, they must have the same number of rows. If you stitch together vertically, they must have the same number of rows.

1 commentaire

Stephen23
Stephen23 le 10 Jan 2015
Small correction: "If you stitch together horizontally, they must have the same number of rows. If you stitch together vertically, they must have the same number of columns".

Connectez-vous pour commenter.

Question posée :

le 9 Jan 2015

Modifié(e) :

le 13 Jan 2015

Community Treasure Hunt

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

Start Hunting!

Translated by