how velocize it? (it's possibile to vectorize it?)
Show older comments
Ntradess =[2 99 1 8 15 67 74 51 58 40
3 80 7 14 16 73 55 57 64 41
3 80 7 20 22 54 56 63 70 47
3 81 7 21 3 60 62 69 71 28
3 81 9 2 9 61 68 75 52 34
4 82 9 83 90 42 49 26 33 65
4 82 9 89 91 48 30 32 39 66
5 85 10 95 97 29 31 38 45 72
6 85 11 96 78 35 37 44 46 53
7 85 12 77 84 36 43 50 27 58
8 86 13 80 84 38 45 51 30 58
8 86 13 82 84 38 45 51 31 58
8 86 13 83 84 38 45 51 31 58
9 87 13 84 84 38 45 51 31 58];
RP_bin=[0 0 1 0 0 1 0 0 1 0 0 1 0 0]';
period=2;
minTrades=2;
g=find(RP_bin>0);
Ntradess_=Ntradess(g,:);
[r,c]=size(Ntradess_);
MinNtrad=zeros(r,c);
for x=1:c %loop colonne
for i=period+1:r
a=Ntradess_(i,x); %n:trade del idx attuale
if a>minTrades
a=find(flip(Ntradess_(1:i-1,x))<=(a-minTrades),1);
if ~isempty(a)
MinNtrad(i,x)= i-a; %MEMORIZZO la posizione della schiera per avere in mintrades richiesti
end
end
end
end
4 Comments
Dyuman Joshi
on 30 Jul 2023
What is your motivation behind wanting to vectorize the code above?
Walter Roberson
on 30 Jul 2023
You could save some coding effort if you were to use
a = find(Ntradess_(1:i-1,x))<=(a-minTrades), 1, 'last');
if ~isempty(a)
MinNtrad(i,x) = a;
end
The change in logic might make it easier to figure out how to vectorize.
pipin
on 30 Jul 2023
Accepted Answer
More Answers (0)
Categories
Find more on Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!