The Code Runs Too Long, Should I Abort It?

1 回表示 (過去 30 日間)
Ashvin Hamzah Driwantara
Ashvin Hamzah Driwantara 2016 年 12 月 14 日
編集済み: Adam 2016 年 12 月 14 日
I run this code and I think it runs too long. Any solution?
c6 and c3 is matrix with 3300x2200 grids.
if true
e=0.06+c6;
f=c3;
[m,n]=size(f);
for i=1:m;
for j=1:n;
if f(i,j)>e;
t(i,j) = 1;
else
t(i,j) = 0;
end
end
end
end

採用された回答

Adam
Adam 2016 年 12 月 14 日
編集済み: Adam 2016 年 12 月 14 日
Can't you just replace the whole thing with:
t = c3 > e;
or
t = double( c3 > e );
if you want the 0s and 1s as doubles rather than logicals?
doc vectorization
gives an introduction to this very powerful alternative to nested for loops which is almost always noticeably faster too.
  2 件のコメント
Ashvin Hamzah Driwantara
Ashvin Hamzah Driwantara 2016 年 12 月 14 日
u mean like this?
if true
e=0.06+c6;
f=c3>e;
[m,n]=size(f);
for i=1:m;
for j=1:n;
if f(i,j)==1;
t(i,j) = 1;
else
t(i,j) = NaN;
end
end
end
end
Adam
Adam 2016 年 12 月 14 日
編集済み: Adam 2016 年 12 月 14 日
No, I mean just literally replace everything after
e=0.06+c6;
with that one line:
t = c3 > e;

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by