[Scilab-users] Converting the result of strchr() to a boolean (scilab: to exclusive) test?

scilab.20.browseruk at xoxy.net scilab.20.browseruk at xoxy.net
Sat Apr 2 16:05:42 CEST 2016


Thanks Samuel. (Glad there's someone else around on the weekend.)

I would never have thought to look at grep() for this purpose. 
One of my most used languages (Perl) also has a built-in called grep(), but it serves a quite different purpose there.

But, it does raise another question that has been on the back of my mind.

The raw data I'm graphing is raw magnetic curve (BH curve) data, that generically look something like this:

    http://www.material-sys.com/image/product/b-hHysteresisCurveEn.png

Ie. It contains values describing the rise from 0,0 to point a, then the full hysteresis loop a -> d -> a.

I want to be able to plot only the initial magnetisation curve (0,0 -> a); and at the moment I've opted for a crude selection mechanism of:

        [ m, k2 ] = max( b );
        [ m, k1 ] = max( h );
        k = min( k1, k2 );
        h = h( 1:k ); 
        b = b( 1:k );

That is, find the index of the maximum value of both vectors, choose the lowest of the two maximums and then subset both vectors accordingly. That works reasonably well, but not for all curves. 

What I think would be a better selection criteria is to consider the points in successive pairs and set the cut-off whenever either coordinate ceases to be strictly increasing.

In Perl I would use a (library) function called reduce() for that. In Haskell I think it is called fold() (foldr() or foldl() ).

How would you go about that in SciLab?

Cheers, Buk.


> -----Original Message-----
> From: scilab.browseruk.bb30c473ec.sgougeon#free.fr at ob.0sg.net
> Sent: Sat, 2 Apr 2016 15:28:20 +0200
> To: users at lists.scilab.org
> Subject: Re: [Scilab-users] Converting the result of strchr() to a
> boolean (scilab: to exclusive) test?
> 
> Hello,
> 
> Le 02/04/2016 15:19, scilab.20.browseruk at xoxy.net a écrit :
>> I wan't to check a string for the presence of a particular character,
>> which strchr() does perfectly:
>> 
>> -->strchr( 'fred', 'r' )
>>   ans  =
>>   red
> It is not really strchr() 's purpose, rather the grep() one:
> 
> if grep('fred','r') ~= []
>      disp("found")
> else
>      disp("not found")
> end
> 
> Samuel
> 
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users

____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
Check it out at http://www.inbox.com/marineaquarium






More information about the users mailing list