having trouble with number displays in matrix

2 ビュー (過去 30 日間)
Gregory Power
Gregory Power 2019 年 6 月 24 日
コメント済み: Gregory Power 2019 年 6 月 24 日
I am having a problem with the way numbers are being displayed in a matrix from a while loop. I am trying to calculate basic interest increases in a bank account for a number of years and at the 4th year the values change to some sort of scientific notation. I have tried set the format to compact as this is what I understand to be the default format for matlab to be. I have attached my code and here is a snip of my output. What can I do to fix this?
2 1210
3 1331
1.0e+03 *
0.0040 1.4641
1.0e+03 *
0.0050 1.6105
a=1000;
r=0.1;
bal=a;
year=0;
disp('Year Balance')
while bal<a*2
bal=bal+r*bal;
year=year +1;
disp([year bal])
end

採用された回答

Guillaume
Guillaume 2019 年 6 月 24 日
編集済み: Guillaume 2019 年 6 月 24 日
format compact only affects the line spacing of the display. It doesn't affect how numbers are displayed.
I tend to use format longg or format shortg. Both should get rid of the scientific notation.
  1 件のコメント
Gregory Power
Gregory Power 2019 年 6 月 24 日
Thank you. I guess I was a mistaken. and thank you for directing me to the documentation and answering the question.

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

その他の回答 (2 件)

Himanshu Rai
Himanshu Rai 2019 年 6 月 24 日
編集済み: Himanshu Rai 2019 年 6 月 24 日
Since you are having trouble displaying year as integers, you can try this
a=1000;
r=0.1;
bal=a;
year=0;
disp('Year Balance')
while bal<a*2
bal=bal+r*bal;
year=year +1;
disp([int32(year) bal])
end

vidhathri bhat
vidhathri bhat 2019 年 6 月 24 日
Hi
Try using
format long g
This will suppress scientific notation.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by