フィルターのクリア

For loop

1 回表示 (過去 30 日間)
harjan
harjan 2011 年 8 月 16 日
hi 2 all, Can anyone say how to reduce execution time of 'for loop' in matlab How to replace for loop?
  2 件のコメント
Andrei Bobrov
Andrei Bobrov 2011 年 8 月 16 日
your cod with example
harjan
harjan 2011 年 8 月 16 日
Thx a lot Here is my coding Pls say how to Change this "for loop"
[x y]=size(ima); %ima is 1600x1600 image
for i=1:x
for j=1:y
x(i,j)=sign(ima(i,j));
u1(i,j)=255*x(i,j);
...
...
end
end
It takes some amount of time to execute ....How to replace this Tell your suggestions......

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2011 年 8 月 16 日
u1 = 255*sign(ima);
but you get the array size is 1600 x 1600, with values of -255, 0 and 255
ADD on comments
if i1 and j1 integers from 1 to 1600, we obtain an array of 1600 by 1600, consisting of ones, in it case use
i1 = linspace(0,1,6);
j1 = i1;
T=cos(2*pi*repmat(i1',1,numel(j1))).*cos(2*pi*repmat(j1,numel(i1),1)); % 1 variant
T = bsxfun(@times,cos(2*pi*i1'),cos(2*pi*j1)); % 2 variant
T = cos(2*pi*i1')*cos(2*pi*j1);% 3 variant
  1 件のコメント
harjan
harjan 2011 年 8 月 16 日
But how to change if this is in for loop
T(i,j)=(cos(2*pi*i)) * (cos(2*pi*j)); %for i,j varies from 1 to 1600
Thx in advance

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 8 月 16 日
The one sure way to reduce the execution time of a for loop is to eliminate that section of code.
Anything else depends on exactly what your for loop contains. There are some for loops that are now faster than vectorizing or using one of the library routines -- faster even than using a mex routine.
  1 件のコメント
harjan
harjan 2011 年 8 月 16 日
Thx a lot Here is my coding Pls say how to Change this "for loop"
[x y]=size(ima); %ima is 1600x1600 image
for i=1:x
for j=1:y
x(i,j)=sign(ima(i,j));
u1(i,j)=255*x(i,j);
...
...
end
end
It takes some amount of time to execute ....How to replace this Tell your suggestions......

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by