How can I make my code run faster?

Hi,
Hope someone can help.
I would like to improve my code and make it run faster, but I'm not sure what I need to do.
%size of d 31003x50x13
for anim=1:size(d,3)
for trl=1:size(d,2)
for i=1:size(d,1)
if d(i,trl,anim) >= 0.05
C(i,trl,anim)= 1;
elseif -0.05<d(i,trl,anim) && d(i,trl,anim)<0.05
C(i,trl,anim) = 0;
else d(i,trl,anim) < -0.05
C(i,trl,anim) = -1;
end
end
end
end
Thanks

 採用された回答

KSSV
KSSV 2022 年 11 月 1 日

1 投票

c = zeros(size(d)) ;
idx1 = d >= 0.05 ;
c(idx1) = 1 ;
idx2 = d < -0.05 ;
c(idx2) = -1 ;

1 件のコメント

NA
NA 2022 年 11 月 1 日
Thanks mate!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

NA
2022 年 11 月 1 日

コメント済み:

NA
2022 年 11 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by