フィルターのクリア

Using Log in Matlab

4 ビュー (過去 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 Center および File ExchangeEntering Commands についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by