Problem with Max function in a if loop
Ältere Kommentare anzeigen
So, basically my max function at the end gives me a random number and does not apply my if and else if constraint :/
for i = 1:B
JIM{i} = find(REG{1,i} > 0.5);
end
Ans = [JIM;REG;COEFF];%Merge REG and Coeff together so that we can keep an eye on variables name!
for i = 1:B
for j = 1:C
D{i} = find(Ans{3,i}.tStat(:).^2 > 3.8416);
end
end
BLOG = [Ans;D];
for i = 1:B
SIZE{i} = size(BLOG{4,i});
end
for i = 1:B
if BLOG{1,i} ==1
elseif SIZE{1,i}(1,1) ==test.NumCoefficients
H = max(BLOG{2,:});
end
end
end
4 Kommentare
Walter Roberson
am 30 Mai 2013
There is no such thing as an "if loop". There are "for loop" and "while loop" and "if statement"
Walter Roberson
am 30 Mai 2013
Why would you expect max() of a value you pass in, to apply an "if constraint" ? max() is just going to find the maximum.
Where do you initialize H ? What if elseif does not happen to be true anywhere, then what are you expecting H to be set to afterwards? Are you aware that it looks like you can overwrite H on different iterations of the "for i" loop ?
Walter Roberson
am 30 Mai 2013
Please show size(BLOG) class(BLOG{2,1}) size(BLOG{2,1})
Akzeptierte Antwort
Weitere Antworten (2)
Simon
am 30 Mai 2013
0 Stimmen
2 Kommentare
Walter Roberson
am 30 Mai 2013
I can't tell what the algorithm is intended to be.
I can say, though, that it seems confusing to package things up into Ans and BLOG and then pull out specific elements of those that appear to be intended to correspond to the parts that were packaged together. Instead of BLOG{2,:} why not refer to D{:} ?
Simon
am 31 Mai 2013
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!