extracting values above 0 in an array and putting them in a new array
Show older comments

how can i get a 1x5 array by taking values of non-zero? (e.g. taking the first column and taking the first minimum value greater than zero)?
1 Comment
Walter Roberson
on 3 Jul 2020
Question: for column 4, should the output be 1.6807 as the "first" mininum value that is greater than 0? Or should it be 1.6054 because that is the minimum non-zero value in the row? Or should it be 3.8141 because that is the first non-zero value after the 0 ?
Accepted Answer
More Answers (1)
madhan ravi
on 3 Jul 2020
matrix(matrix <= 0) = inf;
Wanted = min(matrix)
6 Comments
Hatim Altarteer
on 3 Jul 2020
madhan ravi
on 3 Jul 2020
Edited: madhan ravi
on 3 Jul 2020
Huh?
>> matrix = [.1, -1;...
0, .01;...
.03, 0]
matrix(matrix <= 0) = inf
Wanted = min(matrix)
matrix =
0.1000 -1.0000
0 0.0100
0.0300 0
matrix =
0.1000 Inf
Inf 0.0100
0.0300 Inf
Wanted =
0.0300 0.0100
KALYAN ACHARJYA
on 3 Jul 2020
"extracting values above 0 in an array and putting them in a new array"
then I am not getting the question till yet.
madhan ravi
on 3 Jul 2020
Well you need to read the content as well , not the question alone.
Hatim Altarteer
on 3 Jul 2020
Edited: Hatim Altarteer
on 3 Jul 2020
madhan ravi
on 3 Jul 2020
Hatim you need to accept dipak’s answer because he was first before me. I was typing the answer in my phone so didn’t realise there was an answer already.
Categories
Find more on Resizing and Reshaping 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!