Index of value exceeding threshold for each row

9 次查看(过去 30 天)
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.

回答(1 个)

Vinai Datta Thatiparthi
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!

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by