Error in function 'var' while calculating variance

조회 수: 5 (최근 30일)
Emilio Morilla
Emilio Morilla 2016년 4월 26일
댓글: soumya sagar sahoo 2018년 3월 20일
Hello everyone!
I'm new with Matlab, so I hope you're understanding with me.
I'm trying to calculate the variance of a submatrix. So, I do the following:
IMG = imread('figure13.tif');
Sxy = IMG(top_x:top_x+k-1, top_y:top_y+k-1);
local_var = var(var(Sxy));
But, it prints me this error:
Error using var (line 65)
First argument must be single or double.
I don't write the variables top_x , top_y and k in order to make it simple but it takes the submatrix correctly.
I make the same with mean function and it works perfectly. Why is 'var' different? How can I calculate the local variance?
Thanks in advance!
  댓글 수: 1
soumya sagar sahoo
soumya sagar sahoo 2018년 3월 20일
x=double(imread('story_lena_lenna_1.jpg')); you can use this (double function)

댓글을 달려면 로그인하십시오.

채택된 답변

Steven Lord
Steven Lord 2016년 4월 26일
Your image data is stored in one of the integer data types. Convert the data to single precision using the single function or to double precision using the double function before calling var on it.
  댓글 수: 1
soumya sagar sahoo
soumya sagar sahoo 2018년 3월 20일
why double is being used for calculating variance?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by