How to round a result to 1 decimal place.

I have a data of 4096x64 and would like to round it to 1 decimal place. When I use DATA = round(DATA,1), the error 'Too many input arguments' appear. Is there any other way to do this?

Antworten (1)

Adam
Adam am 6 Dez. 2017

1 Stimme

Which version of Matlab do you have?
round( data * 10 ) / 10;
is a fairly standard alternative.

4 Kommentare

Amy Wong
Amy Wong am 6 Dez. 2017
I am using version R2014a.
When I try that, some of my values have 4dp or some with e.
Adam
Adam am 6 Dez. 2017
Bearbeitet: Adam am 6 Dez. 2017
What are the values that end up with 4dp? I would have said that is impossible, off the top of my head...
The option for a 2nd argument to round was added in R2014b
Amy Wong
Amy Wong am 6 Dez. 2017
Bearbeitet: Amy Wong am 6 Dez. 2017
Like if my value is 0.33333, I want to get 0.3. But the result is 0.3000. Is there a way to remove the 0 at the back?
Adam
Adam am 6 Dez. 2017
Bearbeitet: Adam am 6 Dez. 2017
Not every decimal number is precisely representable in a double (after all, there are an infinite number of floating point numbers and clearly there are not an infinite number of bit-representations to represent these).
Why do you need it to be precisely 0.3?
Note: round( 0.3333, 1 ) in later Matlab also gives an answer with a lot of trailing 0s that isn't 100% precise to 1dp.

Melden Sie sich an, um zu kommentieren.

Tags

Gefragt:

am 6 Dez. 2017

Bearbeitet:

am 6 Dez. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by