Using Log in Matlab

조회 수: 7 (최근 30일)
Matt
Matt 2012년 11월 26일
Something strange seems to be happening in Matlab and i dont understand why
if im calculating a matrix called M, using actual numbers lets call them A,B and reading from another matrix say M2;
M = 5*log10(A) - B + M2;
i should if i set A to be 1000 get 3 minus two numbers right? but i dont, however i do get the expected answer if i hard code the number A in at 1000 just not with the variable, what is the reason for this? im guessing it involves the matrix M2 or something?

답변 (2개)

Thomas
Thomas 2012년 11월 26일
I get the correct result both times
A=1000;
B=3;
M2=[1 2;3 4]
M=5*log10(A)-B+M2
M =
13.00 14.00
15.00 16.00
Now by hard coding the values
M=5*log10(1000)-3+[1 2;3 4]
M =
13.00 14.00
15.00 16.00

Wayne King
Wayne King 2012년 11월 26일
편집: Wayne King 2012년 11월 26일
Can you be more specific with a simple example, you won't get 3, you'll get 15 since you are doing
5*log10(A)
So if A = 1000, the 5*log10(A) is 15. You get 15 - the sum of the two matrices B and M2
B = ones(5,5);
M2 = 2*ones(5,5);
A = 1000;
M = 5*log10(A) - B + M2;
So for the above you get 15- a matrix of ones, that gives you a matrix of 14's. And then you add a matrix of 2's so you get a matrix of 16's.
Not that is different than
M = 5*log10(A) - (B + M2);
In the above you first add the matrix of ones to the matrix of 2's and then subtract that matrix of 3's from 15 to get a matrix of 12's.

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by