So I am averaging the values of a few pixels in a an area specified by the two for loops parameters (l&m). However, I must be staring at this code for too long as it is not entering the nested loop resulting in an average of zero... which it shouldn't be.
The pixel values of 0 & 12 correlate to black and white which is why they are over-written to not be included in the image due to some of the image having text and lines on top of it...
tic
localurl='http://www.ips.gov.au/Images/HF%20Systems/Global%20HF/Ionospheric%20Map/WorldIMap0.gif';
% [stat, h, localurl]=web(localurl);%doesnt have to run this line
[mat,map]=imread(localurl);
colormap(map);%doesnt have to run this line
image(mat);%doesnt have to run this line
c=clock;
year=num2str(c(1));
month=num2str(c(2));
day=num2str(c(3));
hour=num2str(c(4));
min=num2str(c(5));
savename=[year '.' month '.' day '.' hour '.' min '.fig'];
savefig(savename)
.
.
.
s=1;
value=zeros(1,1);
for l=178:184
disp('1st')
for i=224:218
disp('2nd')
value(s)=mat(m,l);
if value(s)~=0 && value(s)~=12
s=s+1;
end
end
end
avg=mean(value(:));
toc

 채택된 답변

Jan
Jan 2014년 6월 30일
편집: Jan 2014년 6월 30일

0 개 추천

  • Your inner loop does not depend on "i", but there is an orphaned "m" without a definition.
  • The inner loop goes fro 224 to 218, but the first index is larger than the second one.
I guess your loop code can be simplified:
data = mat(218:224, 178:184);
avg = mean(data(data ~= 0 & data ~= 12))

댓글 수: 1

Adrienne
Adrienne 2014년 6월 30일
thank you so much, and ya i is m I had been messing with some values and forgot to change it back!

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

추가 답변 (1개)

dpb
dpb 2014년 6월 30일

0 개 추천

s=1;
value=0;
for l=178:184
for i=224:218
value(s)=mat(m,l);
if value(s)~=0 && value(s)~=12
s=s+1;
end
end
end
avg=mean(value(:));
value(s)=mat(m,l);
What's m??? It's never update in the loop so you're always looking at the same pixel. Or, looking again I suppose you meant to write
for m=224:218
instead of i for the inner loop.
The above could be simply
c1=178; c2=184;
r1=224; r2=218;
avg=mean(mat(mat(r1:r2,c1:c2)~=0 & mat(r1:r2,c1:c2)~=12));

카테고리

도움말 센터 및 File Exchange에서 Images에 대해 자세히 알아보기

질문:

2014년 6월 30일

댓글:

2014년 6월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by