Ich versuche, die Bewegung von Punkten mit objektorientiert zu zeichnen. Ich erzeuge Punkte an der Anfangsposition, füge dann ihre Position einem Vektor hinzu und gebe ihnen Eigenschaften. Es gibt ein 1000x1000 Raster als Hintergrund.Matlab - OOP Variablen aktualisieren nicht zur Liste
uav1 = uavclass([10,10,10]);
uav2 = uavclass([-10,-10,-10]);
uav3 = uavclass([20,20,20]);
uav4 = uavclass([-20,-20,-20]);
uav5 = uavclass([30,30,30]);
XY = [];
XY(:,1) = [uav1.position(1),uav2.position(1),uav3.position(1),uav4.position(1),...
uav5.position(1),];
XY(:,2) = [uav1.position(2),uav2.position(2),uav3.position(2),uav4.position(2),...
uav5.position(2),];
UAVs = plot(XY(:,1), XY(:,2), ...
'Marker', '.', ...
'Color', 'r', ...
'LineStyle', 'none', ...
'MarkerSize', 8);
Wenn ich aber plotten mit
while uav2.charge > 25
uav2.position(1) = uav2.position(1) + uav2.maxHorizSpeed;
uav2.position(2) = uav2.position(2) + uav2.maxHorizSpeed;
uav2.position(2)
uav2.charge = uav2.charge - 1;
pause(0.5)
set(UAVs, 'XData', XY(:,1), 'YData', XY(:,2));
end
drawnow
es nicht Handlung tut. Der Wert von uav2.position erhöht sich, aber er nimmt im Vektor XY nicht zu und es findet keine Bewegung statt. Die Klasse ist
classdef uavclass
properties
position = [0,0,0]
charge = 100;
destination = [0,0,0];
maxVertClimb = 2;
maxHorizSpeed = 5;
sensorRange = 25;
unloadingTime = 60;
safeDistance = 5;
chargingTime = 300;
minCruiseAlt = 20;
maxCruiseAlt = 70;
end
methods
function uav = uavclass(pos)
uav.position = pos;
end
end
end