Skip to content

Instantly share code, notes, and snippets.

@gsimard
Created April 17, 2012 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsimard/2407867 to your computer and use it in GitHub Desktop.
Save gsimard/2407867 to your computer and use it in GitHub Desktop.
Problem creating get function for custom Octave object
## octave --version
## GNU Octave, version 3.6.1
## file: @triangle/triangle.m
function t = triangle (p1, p2, p3)
if (nargin == 3)
if (isvector(p1) && isreal(p1) && length(p1) == 3 &&
isvector(p2) && isreal(p2) && length(p2) == 3 &&
isvector(p3) && isreal(p3) && length(p3) == 3)
t.p1 = p1;
t.p2 = p2;
t.p3 = p3;
t = class(t, "triangle");
else
error("triangle: expecting real 3d vectors");
endif
else
print_usage();
endif
endfunction
## file: @triangle/get.m
function s = get (t, f)
if (nargin == 1)
s.p1 = t.p1;
s.p2 = t.p2;
s.p3 = t.p3;
elseif (nargin == 2)
if (ischar (f))
switch (f)
case "points"
s = [t.p1 t.p2 t.p3];
otherwise
error ("get: invalid property %s", f);
endswitch
else
error ("get: expecting the property to be a string");
endif
else
print_usage ();
endif
endfunction
# octave interpreter:
addpath("/path/to/folder/containing@triangle")
t = triangle([0 0 0],[1 0 0],[1 1 0])
t = <class triangle>
get(t)
error: octave_base_value::array_value(): wrong type argument `class'
error: get: expecting graphics handle as first argument
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment