Azzera filtri
Azzera filtri

how velocize this code

2 visualizzazioni (ultimi 30 giorni)
Luca Re
Luca Re il 13 Lug 2023
Commentato: Luca Re il 14 Lug 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 Commenti
Rik
Rik il 14 Lug 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 il 14 Lug 2023
oky txk

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by