Convert Fortran to MATLAB

5 ビュー (過去 30 日間)
Syed Arafun Nabi
Syed Arafun Nabi 2022 年 11 月 1 日
コメント済み: Syed Arafun Nabi 2022 年 11 月 1 日
I want to convert the following Fortran code to MATLAB. Any help will be appriciated-
NB = 100
F=0.
DO i=1,NB
[some equations]
IF(abs(xm)<wm)
ym=ye+d*sy
IF(abs(ym)<wm) CYCLE
ENDIF
d=LL/sz
xt=xe+d*sx
IF(abs(xt)>wt) CYCLE
yt=ye+d*sy
IF(abs(yt)>wt) CYCLE
F=F+1.
ENDDO
  2 件のコメント
Rik
Rik 2022 年 11 月 1 日
While completely uncommented, this doesn't look very complicated. What have you tried?
It is also possible to compile Fortran to mex, allowing you to call the Fortran function from Matlab.
Syed Arafun Nabi
Syed Arafun Nabi 2022 年 11 月 1 日
I didn't know about Fortran to mex earlier.
I am stuck in nested loop here & made mistake-
NB = 100;
Ft = 0;
i = 0;
while i<N
[some equations]
if (abs(xm)<wm)
ym=ye+d*sy
if (abs(ym)<wm)
d=LL/sz;
xt=xe+d*sx;
if(abs(xt)>wt)
yt=ye+d*sy
IF(abs(yt)>wt)
F = 1;
end
end
end
end
Ft = Ft+F

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

採用された回答

James Tursa
James Tursa 2022 年 11 月 1 日
編集済み: James Tursa 2022 年 11 月 1 日
Here is the equivalent MATLAB code:
NB = 100;
F = 0;
for i=1:NB
% [some equations]
if( abs(xm) < wm )
ym = ye + d*sy;
if( abs(ym) < wm )
continue
end
end
d = LL/sz;
xt = xe + d*sx;
if( abs(xt) > wt )
continue
end
yt = ye + d*sy;
if( abs(yt) > wt )
continue
end
F = F + 1;
end
However, this code looks a bit strange to me. When you look at all the variables that are being tested within the loop, none of them seem to be calculated from anything that is changing within the loop, unless these changes are within the code block labeled [some equations].
  1 件のコメント
Syed Arafun Nabi
Syed Arafun Nabi 2022 年 11 月 1 日
yes the [some equation] parts contains all the constrains to define the loops. thanks a lot

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFortran with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by