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

Andrew Newell
Andrew Newell 2015년 1월 9일
Are the arguments like P111 all scalars?
dpb
dpb 2015년 1월 9일
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 2015년 1월 9일
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 2015년 1월 11일
It is a multiplication of two by two matrices that consists of complex numbers and integers.
Image Analyst
Image Analyst 2015년 1월 11일
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 2015년 1월 13일
편집: segun 2015년 1월 13일
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 2015년 1월 13일
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 2015년 1월 13일
편집: segun 2015년 1월 13일
Sorry for the trouble , i have checked and corrected it .Thanks as i await your help.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2015년 1월 10일

0 개 추천

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

Stephen23
Stephen23 2015년 1월 10일
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".

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2015년 1월 9일

편집:

2015년 1월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by