In Matlab, how to control the number of decimal digits for displaying in command window?
For example,
>> x=0.4654
x =
0.4654
how to display the value of the variable x as 0.5, 0.47, 0.465 respectively in command window?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t think there is built in rounding to arbitrary places, but you can achieve the rounded result by doing round(x*10^number of places)/10^number of places. This prints out with the trailing zeroes, if you want to get rid of those you have to do a specially formatted print like sprintf to the degrees so in your case you could get the results you want by doing:
I hope that helps!
Edit: If you want to do it for matrices, I’m not sure if there’s a better way but you could just loop over the rows given x as a matrix: