Vectorising a loop so does not contain any loops
1 次查看(过去 30 天)
显示 更早的评论
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!