I'm trying to use object programming in Matlab. I only have one class, and one of its methods is expected to apply its only argument (an array) to modify internal values in the object.
However, I keep getting either "too many input arguments" or lack of some parameters when I call the method.
I have tried lots of tricks I found on the web, but to no avail. I must be missing some fundamental understanding of object programming in Matlab.
Here are the relevant parts of my code.
classdef K3MeshObject
properties
Xs
Ys
Zs
Ts
n
m
end
methods
% constructor:
function obj=K3MeshObject(Xg,Yg,Zg) % g stands for "given".
if nargin == 3
obj.Xs=Xg;
obj.Ys=Yg;
obj.Zs=Zg;
obj.n=min([size(obj.Xs,1),size(obj.Ys,1),size(obj.Zs,1)]);
obj.m=min([size(obj.Xs,2),size(obj.Ys,2),size(obj.Zs,2)]);
obj.Ts=ones(obj.n,obj.m);
end
end
% now the modifying method I cannot get to work:
function K3TransMeshO(obj,K) % << ===== tried with and without the obj argument
for jj=1:obj.n % << ===== signals obj unknown. When obj removed, n unknown.
for ii=1:obj.m
V=K3Euclid(K*[obj.Xs(jj,ii);obj.Ys(jj,ii);obj.Zs(jj,ii);obj.Ts(jj,ii)]);
obj.Xs(jj,ii)=V(1);
obj.Ys(jj,ii)=V(2);
obj.Zs(jj,ii)=V(3);
obj.Ts(jj,ii)=V(4);
end
end
end
end
end
function K3ShowTotem(wind, Xo)
K3Header
% Build the totem
Pillar = K3MeshObjectCopy(K3UnitCube)
Pillar.K3TransMeshO(diag([2, 3, 1, 1])); % <<======= problem call
% I also tried K3TransMeshO(Pillar, diag([2, 3, 1, 1]))