<div dir="ltr"><div><div>Outstanding!<br><br></div>Thanks Stefan,<br><br></div>Berns B.<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Mar 19, 2013 at 12:23 AM, Stefan Du Rietz <span dir="ltr"><<a href="mailto:sdr@durietz.se" target="_blank">sdr@durietz.se</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">But as usual there is a better (faster, simpler) solution without a loop!<br>
<br>
// sort in reverse order and get indices<br>
[ysort, k] = gsort(data(:, 2));<br>
// take indices of the 5 largest values<br>
k = k(1:5);<br>
// keep those data<br>
data = [data(k, :)];<br>
<br>
Regards<span class="HOEnZb"><font color="#888888"><br>
Stefan</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
On 2013-03-18 13:09, Stefan Du Rietz wrote:<br>
--------------------<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Berns,<br>
I am not sure if I understand exactly what you mean.<br>
<br>
Perhaps something like this simplified example (to keep the 5 pairs<br>
with the largest y-values)?<br>
<br>
x = (1:10)';<br>
y = [1:5; 6:10]; y = y(:);<br>
data = [x, y];<br>
th = 1:10;   // threshold values<br>
<br>
data // display the original data<br>
for k=1:length(th)<br>
   index = data(:, 2) > th(k);<br>
   if sum(index) < 5  // too few data values left<br>
     break<br>
   end<br>
   data = data(index, :)  // display this result<br>
end<br>
<br>
Output from the run:<br>
  data  =<br>
     1.     1.<br>
     2.     6.<br>
     3.     2.<br>
     4.     7.<br>
     5.     3.<br>
     6.     8.<br>
     7.     4.<br>
     8.     9.<br>
     9.     5.<br>
     10.    10.<br>
  data  =<br>
     2.     6.<br>
     3.     2.<br>
     4.     7.<br>
     5.     3.<br>
     6.     8.<br>
     7.     4.<br>
     8.     9.<br>
     9.     5.<br>
     10.    10.<br>
  data  =<br>
     2.     6.<br>
     4.     7.<br>
     5.     3.<br>
     6.     8.<br>
     7.     4.<br>
     8.     9.<br>
     9.     5.<br>
     10.    10.<br>
  data  =<br>
     2.     6.<br>
     4.     7.<br>
     6.     8.<br>
     7.     4.<br>
     8.     9.<br>
     9.     5.<br>
     10.    10.<br>
  data  =<br>
     2.     6.<br>
     4.     7.<br>
     6.     8.<br>
     8.     9.<br>
     9.     5.<br>
     10.    10.<br>
  data  =<br>
     2.     6.<br>
     4.     7.<br>
     6.     8.<br>
     8.     9.<br>
     10.    10.<br>
<br>
Regards<br>
Stefan<br>
<br>
<br>
On 2013-03-18 01:25, Berns Buenaobra wrote:<br>
--------------------<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Stefan:<br>
<br>
Maybe I should like to get some insight how to do this.<br>
<br>
What I have is two columns (or 2 column vectors) and they need to go<br>
in pairs say magnitude y and a position in x say P(x,y). Now what I<br>
wanted is to be able to detect peaks from a set threshold value - I<br>
would like to keep 10 values above it in memory and discard the rest.<br>
I I repeat the same action until I only get the highest of all these<br>
column vector magnitudes at the last threshold value. There is a<br>
uniform delta for each of the threshold value I use going from<br>
bottom up.<br>
<br>
Problem: I can detect the peaks alright but how does one ensure that<br>
it sticks to its position pair? Since indexing the magnitude seemed to<br>
a sequential location in memory and not its position?<br>
<br>
Thanks for any help.<br>
<br>
Regards,<br>
Berns B.<br>
USC Physics<br>
<br>
<br>
<br>
<br>
On Mon, Mar 18, 2013 at 5:24 AM, Stefan Du Rietz <<a href="mailto:sdr@durietz.se" target="_blank">sdr@durietz.se</a><br>
<mailto:<a href="mailto:sdr@durietz.se" target="_blank">sdr@durietz.se</a>>> wrote:<br>
<br>
    But this is the ultimate solution without a loop:<br>
<br>
    -->bool2s(y>a) .* b + bool2s(~y>a) .* y<br>
      ans  =<br>
       - 11.  - 6.  - 1.    4.    100.<br>
<br>
    /Stefan<br>
<br>
<br>
    On 2013-03-17 22:05, Stefan Du Rietz wrote:<br>
    --------------------<br>
<br>
        Maybe one of the last two of these four loops was what you<br>
wanted:<br>
<br>
        -->bool2s(y>a)<br>
           ans  =<br>
              0.    0.    0.    0.    1.<br>
<br>
        -->for k=bool2s(y>a), if k, disp(b), else, disp(y), end, end<br>
            - 11.  - 6.  - 1.    4.    9.<br>
            - 11.  - 6.  - 1.    4.    9.<br>
            - 11.  - 6.  - 1.    4.    9.<br>
            - 11.  - 6.  - 1.    4.    9.<br>
              100.<br>
<br>
        -->for k=y, if k>a, disp(b), else, disp(y), end, end<br>
            - 11.  - 6.  - 1.    4.    9.<br>
            - 11.  - 6.  - 1.    4.    9.<br>
            - 11.  - 6.  - 1.    4.    9.<br>
            - 11.  - 6.  - 1.    4.    9.<br>
              100.<br>
<br>
        Here, k takes the value of each element in y:<br>
<br>
        -->for k=y, if k>a, disp(b), else, disp(k), end, end<br>
            - 11.<br>
            - 6.<br>
            - 1.<br>
              4.<br>
              100.<br>
<br>
        Or maybe this is easier to follow:<br>
<br>
        -->for k=1:length(y), if y(k)>a, disp(b), else, disp(y(k)),<br>
        end, end<br>
            - 11.<br>
            - 6.<br>
            - 1.<br>
              4.<br>
              100.<br>
<br>
        /Stefan<br>
<br>
        On 2013-03-17 20:46, Stefan Du Rietz wrote:<br>
        --------------------<br>
<br>
            Sorry,<br>
            I should have written (?):<br>
<br>
            A multi-element logical array is true (T) only if all<br>
            elements are T.<br>
            -->and(y>a)<br>
               ans  =<br>
                F<br>
<br>
            /Stefan<br>
<br>
            On 2013-03-17 20:35, Stefan Du Rietz wrote:<br>
            --------------------<br>
<br>
                -->y=(5*x)-1<br>
                   y  =<br>
                    - 11.  - 6.  - 1.    4.    9.<br>
<br>
                -->y>a<br>
                   ans  =<br>
                    F F F F T<br>
<br>
                This is F (the first element)<br>
<br>
                /Stefan<br>
<br>
<br>
                On 2013-03-17 20:23, Modestas Bunokas wrote:<br>
                --------------------<br>
<br>
                    If someone will find 2 min of free time, I would<br>
                    be very grateful.<br>
                    I'm<br>
                    somehow getting weird result doing simple<br>
                    operation like:<br>
<br>
                    a=7;  b=100;  x=[-2:1:2];  y=(5*x)-1;<br>
                    if  y>a  then  disp(b);<br>
                          else  disp(y);<br>
                    end<br>
<br>
                    --> - 11.  - 6.  - 1.    4.    9.<br>
<br>
                    Last result (9) is wrong, it should be 100 (b). I<br>
                    fully understand<br>
                    that it's because of lack of my knowledge in<br>
                    programming but in few<br>
                    days I could not solve or even could not find any<br>
                    help. Because of<br>
                    that writing here.<br>
<br>
<br>
                    ______________________________<u></u>___________________<br>
                    users mailing list<br>
                    <a href="mailto:users@lists.scilab.org" target="_blank">users@lists.scilab.org</a><br>
<mailto:<a href="mailto:users@lists.scilab.org" target="_blank">users@lists.scilab.org</a><u></u>><br>
                    <a href="http://lists.scilab.org/__mailman/listinfo/users" target="_blank">http://lists.scilab.org/__<u></u>mailman/listinfo/users</a><br>
                    <<a href="http://lists.scilab.org/mailman/listinfo/users" target="_blank">http://lists.scilab.org/<u></u>mailman/listinfo/users</a>><br>
<br>
<br>
                ______________________________<u></u>___________________<br>
                users mailing list<br>
                <a href="mailto:users@lists.scilab.org" target="_blank">users@lists.scilab.org</a> <mailto:<a href="mailto:users@lists.scilab.org" target="_blank">users@lists.scilab.org</a><u></u>><br>
                <a href="http://lists.scilab.org/__mailman/listinfo/users" target="_blank">http://lists.scilab.org/__<u></u>mailman/listinfo/users</a><br>
                <<a href="http://lists.scilab.org/mailman/listinfo/users" target="_blank">http://lists.scilab.org/<u></u>mailman/listinfo/users</a>><br>
<br>
<br>
            ______________________________<u></u>___________________<br>
            users mailing list<br>
            <a href="mailto:users@lists.scilab.org" target="_blank">users@lists.scilab.org</a> <mailto:<a href="mailto:users@lists.scilab.org" target="_blank">users@lists.scilab.org</a><u></u>><br>
            <a href="http://lists.scilab.org/__mailman/listinfo/users" target="_blank">http://lists.scilab.org/__<u></u>mailman/listinfo/users</a><br>
            <<a href="http://lists.scilab.org/mailman/listinfo/users" target="_blank">http://lists.scilab.org/<u></u>mailman/listinfo/users</a>><br>
<br>
<br>
        ______________________________<u></u>___________________<br>
        users mailing list<br>
        <a href="mailto:users@lists.scilab.org" target="_blank">users@lists.scilab.org</a> <mailto:<a href="mailto:users@lists.scilab.org" target="_blank">users@lists.scilab.org</a><u></u>><br>
        <a href="http://lists.scilab.org/__mailman/listinfo/users" target="_blank">http://lists.scilab.org/__<u></u>mailman/listinfo/users</a><br>
        <<a href="http://lists.scilab.org/mailman/listinfo/users" target="_blank">http://lists.scilab.org/<u></u>mailman/listinfo/users</a>><br>
<br>
<br>
    ______________________________<u></u>___________________<br>
    users mailing list<br>
    <a href="mailto:users@lists.scilab.org" target="_blank">users@lists.scilab.org</a> <mailto:<a href="mailto:users@lists.scilab.org" target="_blank">users@lists.scilab.org</a><u></u>><br>
    <a href="http://lists.scilab.org/__mailman/listinfo/users" target="_blank">http://lists.scilab.org/__<u></u>mailman/listinfo/users</a><br>
    <<a href="http://lists.scilab.org/mailman/listinfo/users" target="_blank">http://lists.scilab.org/<u></u>mailman/listinfo/users</a>><br>
<br>
<br>
<br>
<br>
______________________________<u></u>_________________<br>
users mailing list<br>
<a href="mailto:users@lists.scilab.org" target="_blank">users@lists.scilab.org</a><br>
<a href="http://lists.scilab.org/mailman/listinfo/users" target="_blank">http://lists.scilab.org/<u></u>mailman/listinfo/users</a><br>
<br>
</blockquote>
<br>
______________________________<u></u>_________________<br>
users mailing list<br>
<a href="mailto:users@lists.scilab.org" target="_blank">users@lists.scilab.org</a><br>
<a href="http://lists.scilab.org/mailman/listinfo/users" target="_blank">http://lists.scilab.org/<u></u>mailman/listinfo/users</a><br>
<br>
</blockquote>
<br>
______________________________<u></u>_________________<br>
users mailing list<br>
<a href="mailto:users@lists.scilab.org" target="_blank">users@lists.scilab.org</a><br>
<a href="http://lists.scilab.org/mailman/listinfo/users" target="_blank">http://lists.scilab.org/<u></u>mailman/listinfo/users</a><br>
</div></div></blockquote></div><br></div>