필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

I dont get any value from SigmaNorm_crop(i,j), can anyone help me?

조회 수: 3 (최근 30일)
Hana
Hana 2014년 8월 7일
마감: MATLAB Answer Bot 2021년 8월 20일
inc=[2 2.5 5 7.5 6.2 3.5 8 12; 14 10 11.5 13 10 9 3 8; 6.7 8 7 5 4 3 7 12.7; 12 13.5 14 9.5 13 7.5 6.5 5.5]
lc= [10 11 2 1 3 6 8 3;3 2 2 3 4 1 13 1;2 16 3 3 10 9 4 3;5 4 2 2 3 3 9 4]
radar=[ 1 2 3 4 5 6 7 8;8 7 6 5 4 3 2 1 ;1 2 3 4 5 6 7 8;8 7 6 5 4 3 2 1]
ME_crop = nanmean(radar(inc >= 6.5 & inc <= 7.5 & (lc == 2 | lc == 4 | lc == 3)));
SD_crop = nanstd(radar(inc >= 6.5 & inc <= 7.5 & (lc == 2 | lc == 4 | lc == 3)));
for ii=2:14;
me_crop(ii,1) = nanmean(radar(inc >= ii-0.5 & inc < ii+0.5 & (lc == 2 | lc == 4 | lc == 3)));
sd_crop(ii,1) = nanstd (radar(inc >= ii-0.5 & inc < ii+0.5 & (lc == 2 | lc == 4 | lc == 3)));
for i = 1:4
for j=1:8
SigmaNorm_crop = -9999*ones(4,8);
if (inc >= ii-0.5 & inc < ii+0.5 & (lc == 2 | lc == 4 | lc == 3));
SigmaNorm_crop(i,j)=ME_crop+SD_crop*(radar(i,j)-me_crop(ii,1))./sd_crop(ii,1);
end
end
end
end

답변 (1개)

Geoff Hayes
Geoff Hayes 2014년 8월 7일
편집: Geoff Hayes 2014년 8월 7일
Hana - the problem is with your condition
(inc >= ii-0.5 & inc < ii+0.5 & (lc == 2 | lc == 4 | lc == 3))
If you put a breakpoint at the if statement for this condition and run the code, then you can print out the results of this condition and observe that it is
K>> inc >= ii-0.5 & inc < ii+0.5
ans =
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
What exactly does or should this condition mean? For example, the inc >= ii-0.5 are you trying to say if there is at least one value in the matrix inc that is greater than or equal to ii-0.5 then this part is true? Or are you trying to condition on something else?
As well, you reinitialize SigmaNorm_crop on every j iteration, so anything that you may have set previously (if the conditions were ever to evaluate to true) would be lost. At the very least, this matrix should be initialized on every ii iteration, but then you would still lose the data on the next ii. You probably want to do something like this instead
SigmaNorm_crop = -9999*ones(4,8,14-2+1);
for ii=2:14
me_crop(ii,1) = nanmean(radar(inc >= ii-0.5 & inc < ii+0.5 & ...
(lc == 2 | lc == 4 | lc == 3)));
sd_crop(ii,1) = nanstd (radar(inc >= ii-0.5 & inc < ii+0.5 & ...
(lc == 2 | lc == 4 | lc == 3)));
for i = 1:4
for j=1:8
if evaluatesToTrue
SigmaNorm_crop(i,j,ii) = something
end
end
end
end
  댓글 수: 2
Hana
Hana 2014년 8월 7일
Thanks for your answer. I am trying to say if inc >= ii-0.5 & inc < ii+0.5 condition on matrix inc is valid and the pixel value on lc matrix is 2 or 3 or 4 then calculate SigmaNorm_crop.
let me say in this way: for example if inc=5 then it should look at the line number 5 (ie. ii=5) in me_crop and sd_crop. get this value and put it in the frmula to calculate SIgmaNorm_crop. what you wrote creates SigmaNorm_crop 14 times. I need to calculate SigmaNorm for every pixel on one matriy only. My reall data is about 13000*10000. its a huge file.
Geoff Hayes
Geoff Hayes 2014년 8월 7일
But inc can never be just five (from your example of inc=5) since it is a matrix. Are you saying that if inc contains at least one element that is greater than or equal to ii-0.5 AND less than ii+0.5, then the condition should evaluate to true?
And by lc==2 do you mean that lc contains at least one element that is equal to 2?
If that is the case, then your condition could be converted to the following
if ~isempty(find(inc >= ii-0.5 & inc < ii+0.5)) && ...
(~isempty(find(lc,2)) || ~isempty(find(lc,3)) || ...
~isempty(find(lc,4)))
In fact, since your condition doesn't depend on i and j, then you could do this first before evaluating the two inner for loops
SigmaNorm_crop = -9999*ones(4,8);
for ii=2:14
me_crop(ii,1) = nanmean(radar(inc >= ii-0.5 & inc < ii+0.5 & ...
(lc == 2 | lc == 4 | lc == 3)));
sd_crop(ii,1) = nanstd (radar(inc >= ii-0.5 & inc < ii+0.5 & ...
(lc == 2 | lc == 4 | lc == 3)));
if ~isempty(find(inc >= ii-0.5 & inc < ii+0.5)) && ...
(~isempty(find(lc,2)) || ~isempty(find(lc,3)) || ...
~isempty(find(lc,4)))
for i = 1:4
for j=1:8
SigmaNorm_crop(i,j) = something
end
end
end
end
Even the above can be refined: the conditions involving lc can be determined outside of the outer for loop since it does not depend on ii.
Note that you will still need to address how to initialize and update SigmaNorm_crop.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by