Undefined function or variable 'm'

I'm newer using matlab I wrote this code,but i have a error Plz help me,thanks
A=imread('21_training.tif');
B=A(:,:,2);
%opening disk = 3
se=strel('disk',3);
C=imopen(B,se);
%co-occurrence matrix
glcm=graycomatrix(C,'NumLevel',256);
p=glcm/sum(glcm(:));
%mean pi,pj and standard deviation pi,pj (mean pi=mean pj)
for i=1:256
for j=1:256
m=m+double(i).*p(i,j);
end
end
error: Undefined function or variable 'm'

 採用された回答

ES
ES 2013 年 11 月 8 日

0 投票

It could help if you could format your code using the {}Code button in the question edit window. the Problem is m is not defined. You have done
m=m+(something)
in the first iteration (i=1 and j=1), matlab tries to add value of double(i).*p(i,j) to m. but it does not know what m is.
Initialize m to something (say 0) and try.

その他の回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 8 日
編集済み: Azzi Abdelmalek 2013 年 11 月 8 日

0 投票

The for loop
m=0
for i=1:256
for j=1:256
m=m+double(i).*p(i,j);
end
end
can be replaced by
m=sum(sum(repmat((1:256)',1,256).*p))
%or
m=sum(sum(bsxfun(@(x,y) x.*y,p,(1:256)')));
Andrei Bobrov
Andrei Bobrov 2013 年 11 月 8 日

0 投票

m = sum((1:256)*p)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

Huy
2013 年 11 月 8 日

コメント済み:

Huy
2013 年 11 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by