Using Log in Matlab
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(2 个)
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
0 个评论
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!