フィルターのクリア

can i velocize it? (if possible to vectorize)

2 ビュー (過去 30 日間)
Luca Re
Luca Re 2023 年 10 月 1 日
回答済み: Bruno Luong 2023 年 10 月 1 日
[r,c]=size(DD);
z=find(RP_bin);
filtro=zeros(numel(z),c);
period=3; %value=from 1 to numel(z)
tic
for i=1:c
for ii=period+1:numel(z)
idx=z(ii);
idx2=max(1,MinTrade_Tab(ii,i));
s=DD(idx2:idx,i);
n=any(ismember(s,0));
filtro(ii,i)=n;
end
end
toc
  2 件のコメント
dpb
dpb 2023 年 10 月 1 日
You would stand a far better chance if you explained the objective here and what the input data are instead of expecting folks to ferret it out on their own...
Luca Re
Luca Re 2023 年 10 月 1 日
編集済み: Luca Re 2023 年 10 月 1 日
I posted the complete data I was convinced that not all this information was needed to speed up an algorithm. DD is the time series and I note if there is a value==0 between the 2 indices examined (idx and idx2)
MinTrade_Tab contains index

サインインしてコメントする。

採用された回答

Bruno Luong
Bruno Luong 2023 年 10 月 1 日
On my computer the acceleratoion of Method V2 is more impressive
load('matlab_DD.mat')
load('matlab_minTrades.mat')
load('matlab_RpBin.mat')
[r,c]=size(DD);
z=find(RP_bin);
period = 0 % not provided by OP
period = 0
tic
filtro=zeros(numel(z),c);
for i=1:c
for ii=period+1:numel(z)
idx=z(ii);
idx2=max(1,MinTrade_Tab(ii,i));
s=DD(idx2:idx,i);
n=any(ismember(s,0));
filtro(ii,i)=n;
end
end
toc
Elapsed time is 0.027284 seconds.
% Method V2
tic
[m,n] = size(DD);
k = [-Inf; find(DD==0); Inf];
start = MinTrade_Tab(period+1:numel(z),:);
start = max(start,1);
stop = z(period+1:end);
kstop = stop + m * (0:n-1);
kstart = start + m * (0:n-1);
l1 = discretize(kstart,k,'IncludedEdge','right');
l2 = discretize(kstop,k,'IncludedEdge','left');
filtro2 = l1+1<=l2;
filtro2 = [zeros(period,c); filtro2];
toc
Elapsed time is 0.012275 seconds.
close all
ax1=subplot(1,2,1);
imagesc(filtro)
ax2=subplot(1,2,2);
imagesc(filtro2)
linkaxes([ax1 ax2])
% Check
isequal(filtro, filtro2)
ans = logical
1

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSingle-Rate Filters についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by