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:
finding 95% max value

Subject: finding 95% max value

From: Young Ryu

Date: 10 Aug, 2009 17:16:02

Message: 1 of 5

Hi-

I have an array:
r1=floor(rand(100)*100);

In this array, I want to find 95% highest value and its location (col, row). I was using "sort" function but I felt there would be faster way to do this. Could you help this?

Thanks!

Subject: finding 95% max value

From: dpb

Date: 10 Aug, 2009 17:34:23

Message: 2 of 5

Young Ryu wrote:
> Hi-
>
> I have an array: r1=floor(rand(100)*100);
>
> In this array, I want to find 95% highest value and its location
> (col, row). I was using "sort" function but I felt there would be
> faster way to do this. Could you help this?

It is an order statistic; hist() or histc() might be useful. Whether
end up faster in end I don't know; didn't try specifically.

--

Subject: finding 95% max value

From: Bruno Luong

Date: 10 Aug, 2009 18:32:03

Message: 3 of 5

"Young Ryu" <ryuyr77@gmail.com> wrote in message <h5pkki$916$1@fred.mathworks.com>...
> Hi-
>
> I have an array:
> r1=floor(rand(100)*100);
>
> In this array, I want to find 95% highest value and its location (col, row). I was using "sort" function but I felt there would be faster way to do this. Could you help this?
>
> Thanks!

With the size 100 x 100, SORT is quite fast and IMO.

You might be interested in the function MAXK for larger array: http://www.mathworks.com/matlabcentral/fileexchange/23576

n = 1000;
r1=rand(n);
cut = round(0.05*numel(r1));

tic
[v loc]=maxk(r1(:),cut); % FEX
[row col] = ind2sub(size(r1),loc(end));
toc % Elapsed time is 0.032094 seconds.
r1(row,col);
clear v loc

tic
[s loc]= sort(r1(:));
[row col] = ind2sub(size(r1),loc(end-cut+1));
toc % Elapsed time is 0.151089 seconds.
r1(row,col);

% Bruno

Subject: finding 95% max value

From: Thomas Clark

Date: 10 Aug, 2009 22:51:18

Message: 4 of 5

If it doesn't have to be exactly the 95%, then 2*standard deviation of an array will give you a value which is approximately at the 95th percentile.

Alternatively, you can use the ranks of values to determine their percentiles
http://en.wikipedia.org/wiki/Percentile
and work from that.

Could you be assured that the point closest to the 95th percentile is unique (your data has some form), or may there be more than one solution (as in the example you posed)?


"Young Ryu" <ryuyr77@gmail.com> wrote in message <h5pkki$916$1@fred.mathworks.com>...
> Hi-
>
> I have an array:
> r1=floor(rand(100)*100);
>
> In this array, I want to find 95% highest value and its location (col, row). I was using "sort" function but I felt there would be faster way to do this. Could you help this?
>
> Thanks!

Subject: finding 95% max value

From: TideMan

Date: 10 Aug, 2009 23:01:42

Message: 5 of 5

On Aug 11, 10:51 am, "Thomas Clark" <t.cl...@remove.spamcantab.net>
wrote:
> If it doesn't have to be exactly the 95%, then 2*standard deviation of an array will give you a value which is approximately at the 95th percentile.
>

Bunkum, balderdash, poppycock and hooey!!

2*standard deviation + mean gives the 97.5 percentile of normally
distributed, random variables.
For such a distribution, there is a 95% probability that a number with
lie between mean - 2*SD and mean + 2*SD

Tags for this Thread

No tags are associated with 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