var(I(:)); Means?

Hi, I have this problem
signal_var = var(I(:));
What's the meaning of the code below?
var(I(:));
Thanks a lot :)

9 个评论

You can execute the code piece by piece, just highlight for example I(:) and press F9.
Also, doc var.
Superb
Superb 2012-5-5
F9 doesn't show anything, it only show a lot of long code inside the Command Window, can I know why? Thanks
And is there any correct way to debug? TQ :)
F9 executes the code.
Superb
Superb 2012-5-6
I think F5 is the one? Lolx..
The key depends upon the operating system. For Linux it is F5 .
Superb
Superb 2012-5-6
I use Windows 7 :)
I didn't know that. By the way, in WIndows 7 F9 will evaluate the selection (e.g. the line of code you're on in the command history panel - just right click and see), while F5 says to run the whole m-file, or to continue running non-stop if you had stopped somewhere inside the m-file. So for Windows 7 they both work. Of course this has not much to do with the original question, which was answered twice below (but apparently unseen by Superb) in clear and explicit detail.
Ah, I misread. I never used "evaluate selection".
I never do either.

请先登录,再进行评论。

回答(2 个)

the cyclist
the cyclist 2012-5-5

1 个投票

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

1 个投票

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?

类别

帮助中心File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

提问:

2012-5-5

Community Treasure Hunt

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

Start Hunting!

Translated by