comp.lang.ada
 help / color / mirror / Atom feed
* Emulation of MatLab functions?
@ 2001-07-17  0:28 Steve O'Neill
  2001-07-17 10:44 ` Jacob Sparre Andersen
  0 siblings, 1 reply; 2+ messages in thread
From: Steve O'Neill @ 2001-07-17  0:28 UTC (permalink / raw)


I'm just wondering whether anyone has ever attempted an Ada
implementation which would emulate some of the powerful vector
manipulation routines provided by Matlab.  I need to take a matlab model
and implement it in Ada95 and it would certainly be nice to have some of
the tools that Matlab provides.

I'm particularly interested in the functions such as find(<vector>) and
sort(<vector>). Find allows one to apply a criteria against an entire
array of values and it returns another array which contains the values
that pass the test (or references to these).  Sort does as you would
expect - returns the array in sorted order.  Some very powerful
functionality!

Anyway, I've got some thoughts on how I might emulate these in Ada but I
thought that I would query the Ada crew to see if I could save myself
some time and effort.

Thanks,
Steve




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Emulation of MatLab functions?
  2001-07-17  0:28 Emulation of MatLab functions? Steve O'Neill
@ 2001-07-17 10:44 ` Jacob Sparre Andersen
  0 siblings, 0 replies; 2+ messages in thread
From: Jacob Sparre Andersen @ 2001-07-17 10:44 UTC (permalink / raw)


Steve:

John Thornley published a sorting package somewhere.

Find should be pretty easy to implement. Something along the
lines of:

   --  The following is distributed according to the GNU GPL
or the
   --  ADCL (when it is finished).

   generic
      type Element_Type is private;
      type Element_Array is array (Integer range <>) of
Element_Type;
      with function Match (Item : Element_Type) return
Boolean;
   function Find (Source : Element_Array) return
Element_Array;

   function Find (Source : Element_Array) return
Element_Array is
      Match_Count : Natural := 0;
      Matches     : array (Source'Range) of Boolean;
   begin
      for Index in Source'Range loop
         Matches (Index) := Match (Source (Index));

         if Matches (Index) then
            Match_Count := Match_Count + 1;
         end if;
      end loop;

      declare
         Result       : Element_Array (1 .. Match_Count);
         Target_Index : Natural := 0;
      begin
         for Source_Index in Source'Range loop
            if Matches (Source_Index) then
               Target_Index := Target_Index + 1;
               Result (Target_Index) := Source
(Source_Index);
            end if;
         end loop;

         return Result;
      end;
   end Find;

Jacob
-- 
Warning: Dates in calendars are closer than they appear.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-07-17 10:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-17  0:28 Emulation of MatLab functions? Steve O'Neill
2001-07-17 10:44 ` Jacob Sparre Andersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox