How to check if each row of a large matrix exists in a large cell array and then save the matching cell in a separate variable?

조회 수: 1 (최근 30일)
I have attached two datasets: 1) All_cluster.mat: this consists a cell array in which each cell consists of certain data as m-by-n matrix. and 2) sorteddata.mat: this consists of a large matrix; each row in this matrix (i.e. columns 2, 3 and 4) is a member of one of the cells in that given cell array i.e. All_cluster.mat. I want to sort out the cells in All_cluster.mat by comparing each row of the matrix i.e. sorteddata.mat (if there is match). I have used a loop but it is taking so much of time:
matchingCells ={};
for i = 1:size(sorteddata(:, 2:end), 1)
% Loop through each cell in the cell array
for j = 1:length(All_cluster)
% Check if the current row of sorteddata matches with any row in the current cell
if all(ismember(All_cluster{j}(:,[1,2,5]), sorteddata(i, 2:end)))
% If a match is found, store the cell in the matchingCells cell array
matchingCells{end+1} = All_cluster{j};
end
end
end
Can anyone suggest a code that would take less time?

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by