필터 지우기
필터 지우기

trying to create objects in a for loop

조회 수: 2 (최근 30일)
jeff wu
jeff wu 2012년 3월 31일
hi, i get an error but i dont understand why this isnt working
liste = [node(1,2)]%;subdiv(xkoord);
for i=2:4
liste(i+1) = node(1,2)%;subdiv(xkoord);
end
classdef node
properties
x;
y;
bearing=0;
end % properties
methods
function obj = node(x,y)
obj.x=x;
obj.y=y;
end%functions
end%methods
end %class
??? Input argument "x" is undefined.
Error in ==> node>node.node at 9 obj.x=x;
at the second call in the for it crashes
thanks for help

답변 (1개)

Jim Hokanson
Jim Hokanson 2012년 3월 31일
Matlab is trying to construct space for the object before you actually construct the object. In other words, Matlab is calling your constructor without any input arguments. If you add the following to your constructor call and you should be fine
if nargin == 0
return
end

카테고리

Help CenterFile Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by