Вопрос

I have a matlab function to detect the index array that has data below threshold

the result index_list will be in n x 2 matrix where
index_list(i,1) = row
index_list(i,2) = column

that have element array < threshold

Since I don't know how many result would be in index_list

function [index_list] = pickindex(Array,Threshold)
index = 1;
for i= 1:size(Array,1)
    for j = 1:size(Array,2)
        if(Array(i,j) <= Threshold)
            index_list(index,1)=i;
            index_list(index,2)=j;
            index = index +1;
        end
    end
end

This code is working but is there any other suggestion to improve the code?

Это было полезно?

Решение

That sounds like the same thing as:

[r, c] = find(Array <= Threshold);
index_list = [r, c];
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top