Index of value exceeding threshold for each row
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I got this problem:
Lets say I have this matrix [ 1 4 7 19 23 60 79 81 100 90 57 43 , 2 5 7 20 51 77 84 90 101 105 88 56, ...]
I need to find the index of the first value in each row exceeding the threshold of 80.
So for the first row it will be 8 , the second row will be 7, etc.
My matrix consist of 144 columns and 80000 rows. So my output will be a single column with 80000 rows.
0 Commenti
Risposte (1)
Vinai Datta Thatiparthi
il 3 Feb 2020
Hello Boris,
This simple approach could solve the problem -
values = [ 1 4 7 19 23 60 79 81 100 90 57 43; 2 5 7 20 51 77 84 90 101 105 88 56]; %Your input values
% Note: In MATLAB, rows in matrices are seperated by a semicolon symbol and not the comma symbol
indices = zeros(size(values, 1), 1); %Array to hold the final outputs
threshold = 80; %Threshold value
for i=1:size(values, 1)
greaterThan = find(values(i,:) > threshold); %find function returns array of indices of ...
% all the values that are greater than the threshold
indices(i) = greaterThan(1); %We only need the first such index
end
Hope this helps!
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!