|
"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
|