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