Index of value exceeding threshold for each row

9 visualizaciones (últimos 30 días)
Boris
Boris el 30 de En. de 2020
Respondida: Vinai Datta Thatiparthi el 3 de Feb. de 2020
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.

Respuestas (1)

Vinai Datta Thatiparthi
Vinai Datta Thatiparthi el 3 de Feb. de 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!

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by