Vectorising a loop so does not contain any loops

11 ビュー (過去 30 日間)
nc
nc 2016 年 10 月 25 日
コメント済み: Rena Berman 2017 年 1 月 20 日
Hi I have trouble vectorising a loop, currently I am stuck making the arrarys the same value, any help please?
for n = 1:100
for m = 1:100
A(n,m) = n^3 +m;
if A(n,m)<130
A(n,m)=3*A(n,m);
end
end
end
x = 1:100;
y = 1:100;
[X,Y] = meshgrid(x,y);
F = X.^3 + Y ;
F = 3*(F(F<130)); % trouble is here
disp(F);
isequal(A,F);
  1 件のコメント
Rena Berman
Rena Berman 2017 年 1 月 20 日
(Answers Dev) Restored Question.

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

回答 (1 件)

Matt J
Matt J 2016 年 10 月 25 日
I=F<130;
F(I) = 3*F(I);

カテゴリ

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