Do not use the for loop to calculate the first number greater than 0 in each line
Show older comments
x=randn(10,10)
...
2 Comments
Jan
on 19 Nov 2022
This sounds like a homework question. So please show, what you have tried so far and ask a specific question about Matlab. The forum will not solve your homework, but assist you in case of questions concerning Matlab.
slevin Lee
on 19 Nov 2022
Edited: Jan
on 19 Nov 2022
Accepted Answer
More Answers (1)
Here's one way.
x = randn(10,10)
[~,idx] = min(x<=0,[],2) % note the logical inversion
firstnz = x(sub2ind(size(x),(1:size(x,1))',idx)) % get the values from the array
Categories
Find more on Startup and Shutdown 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!