Problem with Max function in a if loop
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Hadi Hajieghrary
on 30 May 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 Comment
Walter Roberson
on 30 May 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.
More Answers (2)
Simon
on 30 May 2013
2 Comments
Walter Roberson
on 30 May 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{:} ?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!