How to check for a zero in any row of a particular column in an [50000, 50000]?

1 view (last 30 days)
So I have an array of [50000, 50000] full of zeros. I gradually add elements to it by replacing the zeros with the elements. I want to add elements to a randomly picked column such that the element is placed at a lowest position of row available with zero.

Answers (1)

DGM on 27 Apr 2021
Depends what you mean by "lowest position of row".
Consider the example:
firstzerorow = find(A(:,thiscolumn)==0,1,'first');
A(firstzerorow,thiscolumn) = mynumber;
lastzerorow = find(A(:,thiscolumn)==0,1,'last');
A(lastzerorow,thiscolumn) = mynumber;


Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!