Problem with Max function in a if loop
1 Ansicht (letzte 30 Tage)
Ä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
Akzeptierte Antwort
Hadi Hajieghrary
am 30 Mai 2013
As I know, the max function is not going to work on a cell data structure. Try to use a matrix. In your case just simply change '{}' to '()'.
1 Kommentar
Walter Roberson
am 30 Mai 2013
The code has
max(BLOG{2,:})
which uses {} not (). Therefor it is not operating on a cell data structure, not unless BLOG{2,:} stored cell data structures. But BLOG(2,:) appears to be REG and the code has REG{1,i} in the context of a numeric array so BLOG{2,:} should be a list of numeric arrays.
Now, {} expansion of an array is like writing the elements out one by one, so
max(BLOG{2,:})
is like writing
max(BLOG{2,1}, BLOG{2,2}, BLOG{2,3}...)
and so on for however many entries are in BLOG. I'm not sure but I think it might be (B) entries.
max() applied to multiple matrices finds the maximum of each corresponding position, rather than finding the maximum over all of the values. I the maximum over all of the values is desired then the code would have to be
max([BLOG{2,:}])
The code is confusing to read; it seems quite likely to me that it could be written more clearly.
Weitere Antworten (2)
Simon
am 30 Mai 2013
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{:} ?
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!