Is there a Faster alternative to ismember function ?
Mostrar comentarios más antiguos
Hello everybody,
I have a matirx with big size of row.
and with this I want to re-define the "el" variable using the first column of "nd" variable.
I tried to put this place using the ismember function. But I feels it is quite slow... it took about 3 minutes.
Is there a faster function or a way to replace it?
clear; close all; clc;
% nd has 10 by 5.
nd = [1 0 0 0.36 0; ...
2 0 -0.02 0.33 0; ...
3 0 -0.51 0.33 0; ...
4 0 -0.81 0.33 0; ...
5 0 -0.01 0.33 0; ...
6 0 -0.01 0.33 0; ...
7 0 -0.17 0.33 0; ...
8 0 -0.02 0.33 0; ...
9 0 -0.02 0.33 0; ...
10 0 -0.02 0.33 0];
eld = [1 2; 2 3; 3 4; 4 1; 1 3; 1 2];
% To make "el2" variable, I hope to convert the 1 as 1 0 0 0.36 0 from nd variable. and 2 as 2 0 -0.02 0.33 0.
% I tried using for loop as below. It takes quite long time for the matirx with big size of row.
for i=1:length(eld)
ind1 = find(ismember(nd(:,1),eld(i,1))); % find index to get the data row from nd variable.
ind2 = find(ismember(nd(:,1),eld(i,2)));
% re-define the "el" variable using the first column of "nd" variable.
eld2(i,:) = [nd(ind1,1), nd(ind1,2), nd(ind1,3), nd(ind1,4), nd(ind1,5), ...
nd(ind2,1), nd(ind2,2), nd(ind2,3), nd(ind2,4), nd(ind2,5)];
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!