Skip to content

Commit

Permalink
[MATLAB] Copied 'simple' example from Octave
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeandersson committed Apr 16, 2014
1 parent de3d759 commit c45f9b5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Examples/matlab/simple/example.c
@@ -0,0 +1,16 @@
/* File : example.c */

/* A global variable */
double Foo = 3.0;

/* Compute the greatest common divisor of positive integers */
int gcd(int x, int y) {
int g;
g = y;
while (x > 0) {
g = x;
x = y % x;
y = g;
}
return g;
}
7 changes: 7 additions & 0 deletions Examples/matlab/simple/example.i
@@ -0,0 +1,7 @@
/* File : example.i */
%module swigexample

%inline %{
extern int gcd(int x, int y);
extern double Foo;
%}
21 changes: 21 additions & 0 deletions Examples/matlab/simple/runme.m
@@ -0,0 +1,21 @@
# file: runme.m

swigexample

# Call our gcd() function

x = 42
y = 105
g = swigexample.gcd(x,y)
printf("The gcd of %d and %d is %d\n",x,y,g);

# Manipulate the Foo global variable

# Output its current value
swigexample.cvar.Foo

# Change its value
swigexample.cvar.Foo = 3.1415926

# See if the change took effect
printf("Foo = %f\n", swigexample.cvar.Foo);

0 comments on commit c45f9b5

Please sign in to comment.