Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
I dont get any value from SigmaNorm_crop(i,j), can anyone help me?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
Geoff Hayes
el 7 de Ag. de 2014
Editada: Geoff Hayes
el 7 de Ag. de 2014
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 comentarios
Geoff Hayes
el 7 de Ag. de 2014
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.
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!