MATLAB switching between integer and floating numbers in a loop during computation
古いコメントを表示
Hi,
I am wondering what is happening in the following for-loop where the variable is changing from being an integer to float to integer to float even though it is not supposed to (?). Don't know what I am missing here.
clc;clear;
for i = 4 : 0.1 : 5
sd=i*1e-09;
start_cell=sd*1e10+1
end
1 件のコメント
Stephen23
2023 年 1 月 19 日
"I am wondering what is happening in the following for-loop where the variable is changing from being an integer to float to integer to float even though it is not supposed to"
It isn't. The value is floating point the entire time.
"Don't know what I am missing here."
The behavior of floating point numbers and how MATLAB displays floating point numbers: the values with no trailing zeros are exactly that value, the others have some accumulated error.
採用された回答
その他の回答 (1 件)
Luca Ferro
2023 年 1 月 18 日
0 投票
start_cell is always of type double during the entire execution. You can test it by debugging the code manually or by using the whos command like this:
for i = 4 : 0.1 : 5
sd=i*1e-09;
start_cell=sd*1e10+1;
whos start_cell
end
The 'issue' you are facing is just visual, it depends on how your format is set.
Here you can find how to set and what type of settings you can change for the visualization:
カテゴリ
ヘルプ センター および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!