having trouble with number displays in matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Gregory Power
el 24 de Jun. de 2019
Comentada: Gregory Power
el 24 de Jun. de 2019
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
0 comentarios
Respuesta aceptada
Más respuestas (2)
Himanshu Rai
el 24 de Jun. de 2019
Editada: Himanshu Rai
el 24 de Jun. de 2019
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
0 comentarios
vidhathri bhat
el 24 de Jun. de 2019
Hi
Try using
format long g
This will suppress scientific notation.
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing 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!