Filter löschen
Filter löschen

how velocize this code

2 Ansichten (letzte 30 Tage)
Luca Re
Luca Re am 13 Jul. 2023
Kommentiert: Luca Re am 14 Jul. 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 Kommentare
Rik
Rik am 14 Jul. 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 am 14 Jul. 2023
oky txk

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by