standard deviation of a variable of type uint8

I have a concatenated 3 dimensional cell array "concatenated_3_D= 720*1280*255" of type uint8. How can I find standard deviation of "concatenated_3_D" along its third dimension? Use of Following code line shows an error that First argument must be single or double. >>sd=std(concatenated_3_D,3);

 Akzeptierte Antwort

Star Strider
Star Strider am 11 Jun. 2016

0 Stimmen

You have to convert it to *single or *|double|, then if necessary convert it back to uint8.

3 Kommentare

Thanks for your answer.But I think this conversion process will cause some error (i.e.change in actual data).Is there not any other way than converting the datatype?
Star Strider
Star Strider am 11 Jun. 2016
No, not to compute the standard deviation (or variance).
The reason is that the standard deviation involves subtracting the individual elements from the mean of those elements, resulting in some negative numbers. Negative intermediate results are not possible with any unsigned data type. I would also leave it as a single or double floating point value, rather than converting the standard deviation back to an unsigned data type, even though the standard deviation will be positive.
Do you think the error is in converting from uint8 to double? No, there will not be. All integers can be perfectly represented by a double, unlike some some numbers -- see the FAQ.
Are you worried about converting the standard deviation to a uint8? Yes, that will change the value by up to 1. So if you don't want that, then just use the original double number and don't convert it to uint8 - that was just an optional thing mentioned by Star but you don't have to do it.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by