Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
unexpected behaviour: mean of a large single matrix

Subject: unexpected behaviour: mean of a large single matrix

From: Akim

Date: 30 Apr, 2012 09:20:07

Message: 1 of 5

Dear all: I take the mean of a large single matrix mean(D(:)) and get an incorrect result. When I take the mean in two steps mean(mean(D)) or convert to double mean(double(D(:))) the result is correct. What is the problem here? Many thanks.

>> whos
  Name Size Bytes Class Attributes
  D 9179x9179 337016164 single

>> mean(D(:))
ans = 47.7099

>> mean(mean(D))
ans = 87.6898

>> mean(double(D(:)))
ans = 87.6897

Subject: unexpected behaviour: mean of a large single matrix

From: Bruno Luong

Date: 30 Apr, 2012 09:37:07

Message: 2 of 5

"Akim " <aaa@bbb.ccc> wrote in message <jnllg7$7ro$1@newscl01ah.mathworks.com>...
> Dear all: I take the mean of a large single matrix mean(D(:)) and get an incorrect result. When I take the mean in two steps mean(mean(D)) or convert to double mean(double(D(:))) the result is correct. What is the problem here? Many thanks.
>
> >> whos
> Name Size Bytes Class Attributes
> D 9179x9179 337016164 single
>
> >> mean(D(:))
> ans = 47.7099
>
> >> mean(mean(D))
> ans = 87.6898
>
> >> mean(double(D(:)))
> ans = 87.6897

This behavior is expected due to limited accuracy of single:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/318972

Further related problem:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/274419

Bruno

Subject: unexpected behaviour: mean of a large single matrix

From: Akim

Date: 30 Apr, 2012 09:39:07

Message: 3 of 5

Sorry I should have searched before asking, here is the same problem reproduced in this thread:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/304835#826650

Does any know why this happens for singles but not for doubles?

Subject: unexpected behaviour: mean of a large single matrix

From: Bruno Luong

Date: 30 Apr, 2012 09:46:07

Message: 4 of 5


>
> Does any know why this happens for singles but not for doubles?

As I wrote above [ This behavior is expected due to limited accuracy of single ].

Bruno

Subject: unexpected behaviour: mean of a large single matrix

From: Akim

Date: 30 Apr, 2012 09:46:07

Message: 5 of 5

Thanks Bruno!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us