Matlab: code performance issue Using "ismember"

I need this section of my code to work faster since it is called many times. I'm new to Matlab, and it seems to me that there MUST be a way to do this, which is not so cool. Any help you could give on how to improve the speed of what I have or other functions to see will help me complete this task.

(The task is to get only the rows “alldata”, where the first column is in the set of “minute intervals” in “alldataMinutes”. “Minintervals” is the minimum value of the column “alldata”, increasing by twenty maximum alldata.

minuteintervals= min(alldata(:,1)):20:max(alldata(:,1)); %20 second intervals
alldataMinutes= zeros(30000,4);
counter=1;
for x=1:length(alldata)
    if ismember(alldata(x,1), minuteintervals)
        alldataMinutes(counter,:)= alldata(x,:);
        counter= counter+1;
    end
end
 alldataMinutes(counter:length(alldataMinutes),:)= [];
+3
source share
1

, , :

minuteintervals = min(alldata(:,1)):20:max(alldata(:,1));  %# Interval set
index = ismember(alldata(:,1),minuteintervals);  %# Logical index showing first
                                                 %#   column values in the set
alldataMinutes = alldata(index,:);  %# Extract the corresponding rows

, ISMEMBER , . index , alldata(:,1) 1 (.. true) alldata(:,1), minuteintervals, 0 (.. false) . , , , index, alldataMinutes.

+1

Source: https://habr.com/ru/post/1757889/


All Articles