Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MATLAB] Copied 'simple' example from Octave
- Loading branch information
1 parent
de3d759
commit c45f9b5
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* File : example.i */ | ||
%module swigexample | ||
|
||
%inline %{ | ||
extern int gcd(int x, int y); | ||
extern double Foo; | ||
%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |