var(I(:)); Means?

1 回表示 (過去 30 日間)
Superb
Superb 2012 年 5 月 5 日
Hi, I have this problem
signal_var = var(I(:));
What's the meaning of the code below?
var(I(:));
Thanks a lot :)
  9 件のコメント
Walter Roberson
Walter Roberson 2012 年 5 月 6 日
Ah, I misread. I never used "evaluate selection".
Image Analyst
Image Analyst 2012 年 5 月 6 日
I never do either.

サインインしてコメントする。

回答 (2 件)

the cyclist
the cyclist 2012 年 5 月 5 日
I(:) treats the array I as a column vector (instead of, say, maybe the MxN array that it was). The var() function takes the variance of that column vector. [See "help var" for details.]
(That assumes that you did not define var as a variable name earlier in the code. If var is a variable, then this code is indexing into that variable.)

Image Analyst
Image Analyst 2012 年 5 月 5 日
Superb, normally var() will take the mean of each column of a 2D array and return a row vector where each element is the variance of the corresponding column. The programmer didn't want that - he wanted the variance of the entire array, not a column-by-column variance. So to do that you can use the (:) construct, which basically takes all the elements in an array (of any dimension) and strings them all together in a single 1D list of numbers (called a "column vector"). Once you've done that, then the var() function will operate on the whole array, not column-by-column. Now it will return a single number rather than a 1D row vector of the column variances. Does that explain it well?

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by