Azzera filtri
Azzera filtri

how to aviod the two loops

1 visualizzazione (ultimi 30 giorni)
Qiu Xu
Qiu Xu il 18 Mag 2024
Risposto: Voss il 18 Mag 2024
I have a code:
x=linspace(-10,10,10001);
y=linspace(-5,5,20001);
A=[];
for j=1:length(x)
for k=1:length(y)
A=[A;x(j),y(k)];
end
end
The computation is very slow due to the two loops, so How can I aviod the two loops in this code?
Thanks very much!

Risposte (1)

Voss
Voss il 18 Mag 2024
[X,Y] = meshgrid(x,y);
A = [X(:),Y(:)];

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by