Problem with Max function in a if loop
显示 更早的评论
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 个评论
Walter Roberson
2013-5-30
There is no such thing as an "if loop". There are "for loop" and "while loop" and "if statement"
Walter Roberson
2013-5-30
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
2013-5-30
Please show size(BLOG) class(BLOG{2,1}) size(BLOG{2,1})
采纳的回答
更多回答(2 个)
Simon
2013-5-30
0 个投票
2 个评论
Walter Roberson
2013-5-30
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
2013-5-31
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!