Hi everyone,
I've this Fortran code:
IF(j<11) THEN
r = FLOAT(j)*0.3
ELSEIF(j<=20)THEN
r = FLOAT(j)/5.0*3.0
ELSEIF(j<=30)THEN
r = FLOAT(j)*2.0
ELSEIF(j<=40) THEN
r =FLOAT(j)*5.0
How can I traslate this code in Matlab? In particular the function "FLOAT"

 採用された回答

DGM
DGM 2021 年 11 月 20 日

0 投票

Unless I'm mistaken, float() would be equivalent to single(); dble() would be equivalent to double().

1 件のコメント

John D'Errico
John D'Errico 2021 年 11 月 20 日
編集済み: John D'Errico 2021 年 11 月 20 日
Note that MATLAB will automatically do a conversion into a double, and since essentially everything is best done using doubles, unless there is a good reason not to do so, just use double is good advice here. All of that means you can essentially just ignore all of the float calls in that code. That is to say...
FLOAT(j)*/5.0*3.0 will be written in MATLAB as simply j/5.0*3.0.
Etc.
As well, the value j = 11, is already represented as a double by default. So if we do this:
j = 11;
whos j
Name Size Bytes Class Attributes j 1x1 8 double
As you can see, j is already stored as a double. It is NOT stored using an explicitly integer form, even though all integers stored as doubles are represented exactly as integers as long as they do not exceed 2^53-1.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeFortran with MATLAB についてさらに検索

製品

リリース

R2019b

質問済み:

2021 年 11 月 20 日

編集済み:

2021 年 11 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by