I am trying to use ismember in a long for loop to identify indices shared between arrays. This is pretty similar to a question that was asked here. Hopefully, an answer can be found for my question.
Below is my script that is taking far too long to run. I've included a sample of my workspace with the important variables here.
The main issue I'm encountering is that using ismember takes far too long. I've tried using parfor to see if that would help but it doesn't mitigate the problem much. If there is a faster way to make the second for loop run faster that would be the type of solution I'm looking for.
As suggested by those in the comments, I have profiled the section of my code in the second for loop. The largest amount of total time spent is from using ismember. The function with the largest self time is sortrows>sort_back_to_front. This is after preallocating the TimeAvg variable.
Lcu =length(count_uni);for i=1:Lcucount = count_uni(i);k = find(count_all==count);% count = 1: 1 unique values% count = 2: 2 unique values% etc.PosAllk = PosAllrep(k,:);A_allk = A_all(k); PVTr_allk = PVTr_all(k);count_allk = count_all(k);if count>1LPAk = length(PosAllk);for j=1:LPAkb = ismember(PosAllrep,PosAllk(j,:),'rows');Aavg = mean(A_all(b)); Pavg = mean(PVTr_all(b));g = ismember(PosAlluni,PosAllk(j,:),'rows');TimeAvg = [TimeAvg;[PosAlluni(g,:),Aavg,Pavg,count]];endelseTimeAvg = [PosAllk,A_allk,PVTr_allk,count_allk];endend