How to find the first zero element in any column of a m by n matrix
38 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a loop that updates certain rows of an MxN matrix depending on certain conditions. At each iteration of the loop I need to find the first empty cell in each row and fill in the matrix from that point on. The problem is that the first zero element is in different locations in each row. I can't figure out how do to this without looping over rows which I want to avoid since the matix is big and it takes forever.
The basic code is something like this where C is the MxN matrix that I want to fill in:
for a = 1:10
A = find(B >= a);
B = find(C(A) == 0);
C(A(B)) = x;
The problem is that the B is a 1byT array that I don't know how to get back to the same dimensions of my original matrix to make the allocation.
Any suggestions are very much appreciated.
Thank you,
1 个评论
dpb
2021-1-19
What is B on entry into the loop?
Is the test for A actually for the loop variable a, 1:10? It's OK if it is, just checking that's really intended, not something else.
What you want filled in the array C is not totally clear -- is this filling in every row from one point on on a row-by-row basis or globally dependent upon the magnitude of a for each step?
What is x? Is if fixed or does it change also?
I think we need to see a sample problem with inputs and the expected output to decipher this precisely enough to have a chance to write code.
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!