Effacer les filtres
Effacer les filtres

how velocize this code

2 vues (au cours des 30 derniers jours)
Luca Re
Luca Re le 13 Juil 2023
Commenté : Luca Re le 14 Juil 2023
%ss is array double
%profit is array double
g=zeros(height(ss));
maxCat=3;
for i=1:height(ss)
z=find(ss(:,i)>0);
if ~isempty(z)
[val,idx]=sort(profit(z),'descend');
ret=idx(1:maxCat);
g(ret,i)=1;
end
end
thank you
  8 commentaires
Rik
Rik le 14 Juil 2023
I'm ignoring the comments Walter gave you to make it more clear what edits I mean:
%ss is array double
%profit is array double
g = zeros(height(ss));
maxCat = 3;
for i=1:height(ss)
z = ss(:,i)>0;
if ~any(z)
[val,idx] = sort(profit(z),'descend');
ret = idx(1:maxCat);
g(ret,i) = 1;
end
end
This will have the same effect as the code you posted.
Luca Re
Luca Re le 14 Juil 2023
oky txk

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by