Vectorising a loop so does not contain any loops

12 Ansichten (letzte 30 Tage)
nc
nc am 25 Okt. 2016
Kommentiert: Rena Berman am 20 Jan. 2017
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);

Antworten (1)

Matt J
Matt J am 25 Okt. 2016
I=F<130;
F(I) = 3*F(I);

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by