Index of value exceeding threshold for each row

9 ビュー (過去 30 日間)
Boris
Boris 2020 年 1 月 30 日
回答済み: Vinai Datta Thatiparthi 2020 年 2 月 3 日
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
Vinai Datta Thatiparthi 2020 年 2 月 3 日
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 Center および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by