Maximum of Multidimensional Array using Flag Matrix
4 次查看(过去 30 天)
显示 更早的评论
Howdy all,
I have a question that should be relatively straight forward, but is giving me a world of trouble. I have two identically sized matrices: one with a range of values and a second matrix that will serve to identify subsets within the first matrix. I have broken down my larger matrices into a fundamental process I'd like to complete, namely: find the maximum of the first matrix only if the second matrix has a zero (no identifier) at that position.
The following simple script should allow for the maximum to be identified, and then I set the identifier matrix to one to eliminate it from the next maximum calculation:
A = magic(7);
B = zeros(7, 7);
Maximum = 49;
while (Maximum > 25)
[Maximum, Index] = max(A(B == 0));
[I, J] = ind2sub(size(A(B==0)), Index);
B(I,J) = 1;
disp([Data, I, J])
end
which works for the first few iterations (Maximum = 49-46), but then produces the wrong index and then removes 1 from the index each additional iteration until reaching a constant value. I'm not sure why MATLAB is behaving like it is, but I would really appreciate any input on this problem. Thanks!
1 个评论
Stephen23
2017-2-25
@Everett625: your code throws errors: first undefined Data, and then when I comment out that line some problem with matrix sizes. Please edit your question and provide a working example if you want help.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!