How to convert "do loop" of fortran to matlab?

2 visualizaciones (últimos 30 días)
adi kul
adi kul el 19 de Mayo de 2016
Respondida: Jos (10584) el 19 de Mayo de 2016
Hello all, I am trying to convert the fortran code to matlab. I am stuck on the following loop of fortran
p=20
q=40
Do 10 x=1,p
t(x)= my equation
10 continue
Do 20 y=1,q
s(y)= my another equation
20 continue
To convert this I used following in matlab:
p=20;
q=40;
for x=1:p
t(x)=my equation;
for y=1:q
s(y)=my another equation;
end
end
But I am not sure if this is the correct way of converting this. Please do suggest.

Respuestas (1)

Jos (10584)
Jos (10584) el 19 de Mayo de 2016
You have converted them to nested for-loops, in which the inner loop is executed multiple times. I think you want two separate loops.
for x=1:p
t(x)=my equation;
end
for y=1:q
s(y)=my another equation;
end

Categorías

Más información sobre Fortran with MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by