Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init, octpy not working for classes yet?
- Loading branch information
Showing
2 changed files
with
43 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,28 @@ | ||
% https://www.mathworks.com/help/matlab/matlab_oop/create-a-simple-class.html | ||
% testing classes in Octave >= 4.0 | ||
|
||
classdef oct2py_class | ||
properties | ||
Value | ||
end | ||
methods | ||
function obj = oct2py_class(val) | ||
if nargin == 1 | ||
if isnumeric(val) | ||
obj.Value = val; | ||
else | ||
error('Value must be numeric') | ||
end | ||
end | ||
end | ||
function r = roundOff(obj) | ||
r = round([obj.Value],2); | ||
end | ||
function r = multiplyBy(obj,n) | ||
r = [obj.Value] * n; | ||
end | ||
function r = plus(o1,o2) | ||
r = o1.Value + o2.Value; | ||
end | ||
end | ||
end |
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,15 @@ | ||
#!/usr/bin/env python | ||
from oct2py import Oct2Py | ||
|
||
val = 3.5 # arbitrary | ||
|
||
with Oct2Py() as oc: | ||
a = oc.oct2py_class() | ||
|
||
a.Value = val | ||
|
||
print(a.Value) | ||
print(a.roundOff) | ||
|
||
|
||
|