not entering nested for loop
古いコメントを表示
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
採用された回答
その他の回答 (1 件)
dpb
2014 年 6 月 30 日
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 についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!