How make this code execute faster?
Afficher commentaires plus anciens
Hi, I'm just trying to figure out how to make this code faster:
N = size(X);
temp = 1:N;
S1 = temp(~ismember(temp,S));%this runs slow
M = X(S,S1); %this runs slos
m = min(M);
cost = sum(m);
X is a square matrix.
Given array of indexes S, I want to extract the submatrix M of S rows, and S1 columns, where S1 are the indexes which are not in S.
Hope I explained it well.
There is a way to achieve the same results faster ?
2 commentaires
madhan ravi
le 9 Juin 2019
Modifié(e) : madhan ravi
le 9 Juin 2019
What is size of X?
Andrea Abbate
le 9 Juin 2019
Modifié(e) : Andrea Abbate
le 9 Juin 2019
Réponse acceptée
Plus de réponses (1)
dpb
le 9 Juin 2019
Try
S1 = setdiff(1:N;S));
What is the precise definition of "runs slow(ly)"? In what context and how have you deduced/concluded this is so?
1 commentaire
Andrea Abbate
le 9 Juin 2019
Modifié(e) : Andrea Abbate
le 9 Juin 2019
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!