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:
how to find the corresponding value to the most repetitive value in hist diagram

Subject: how to find the corresponding value to the most repetitive value in hist diagram

From: SM

Date: 25 Nov, 2009 15:39:07

Message: 1 of 2

I have a set of data vs time. I want to define a treshold for each time block based on the value that has been appeared the most. I created the below code to obtain the most repetitive data point in each time block.
for n=1:size(A,1)
[F(n,:) , Xout(n,:)] = hist(A(n,:),10)
end

To define the treshold I create another code
for n=1:size(A,1)
    index=F(n,:)==max(F(n,:));
    Xout_max(n,:)=X(index);
    treshhold(n,:)=2*(Xout_max(n,:));
end

But this code apparently has some problem since it returens a wrong value for Xout_max. Something might be wrong with reading the corresponding Xout to the index.

For instance in a certain time block:
F=[0 0 0 0 0 1001 0 0 0 0];
Xout=[ -4.5 -3.5 -2.5 -1.5 -0.5 0.5 1.5 2.5 3.5 4.5];

the index will be:
index=[0 0 0 0 0 1 0 0 0 0];

Therefore Xout_max should be 0.5. But due to the error in my code it returens the value as - 4.5 instead.

I appreciate any help from you in advance.
S.M

  
     

Subject: how to find the corresponding value to the most repetitive value in hist diagram

From: kinor

Date: 25 Nov, 2009 16:10:39

Message: 2 of 2

"SM " <khanmoradi@gmail.com> wrote in message <hejj2r$kpc$1@fred.mathworks.com>...
> I have a set of data vs time. I want to define a treshold for each time block based on the value that has been appeared the most. I created the below code to obtain the most repetitive data point in each time block.
> for n=1:size(A,1)
> [F(n,:) , Xout(n,:)] = hist(A(n,:),10)
> end
>
> To define the treshold I create another code
> for n=1:size(A,1)
> index=F(n,:)==max(F(n,:));
> Xout_max(n,:)=X(index);
> treshhold(n,:)=2*(Xout_max(n,:));
> end
>
> But this code apparently has some problem since it returens a wrong value for Xout_max. Something might be wrong with reading the corresponding Xout to the index.
>
> For instance in a certain time block:
> F=[0 0 0 0 0 1001 0 0 0 0];
> Xout=[ -4.5 -3.5 -2.5 -1.5 -0.5 0.5 1.5 2.5 3.5 4.5];
>
> the index will be:
> index=[0 0 0 0 0 1 0 0 0 0];
>
> Therefore Xout_max should be 0.5. But due to the error in my code it returens the value as - 4.5 instead.
>
> I appreciate any help from you in advance.
> S.M
>
>
>

Hi,

F=[0 0 0 0 0 1001 0 0 0 0];
Xout=[ -4.5 -3.5 -2.5 -1.5 -0.5 0.5 1.5 2.5 3.5 4.5];
index = F==max(F)
Xout(index)
gives 0.5 on my machine,

looks like the second line in your loop should be

 Xout_max(n,:)=Xout(n,index);

hth
kinor

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