교통 시뮬레이션을 개발하기 위해 MATLAB 클래스 & 구조체를 사용하려고했습니다. 전에 MATLAB 클래스에서 활발히 작업하지 않았으므로 때때로 약간 까다로워졌습니다. 이 질문은 클래스의 속성 인 구조체 조작과 관련됩니다.MATLAB에서 클래스 속성 인 구조체 조작
는최고 수준의 액세스
vehicles_handle = VehiclesHandle;
vehicles_handle.CreateVehicles(InitialTrafficDensity);
vehicles_handle.vehicles(1)
이제
classdef VehiclesHandle
%VEHICLESHANDLE Summary of this class goes here
% Detailed explanation goes here
properties
active_vehicles_count
vehicles
end
methods (Access = public)
function obj = VehiclesHandle
obj.active_vehicles_count = 0;
obj.vehicles = struct('lane',0,'position',0,'velocity',0);
end
function obj = CreateVehicles(obj,InitialTrafficDensity)
obj.active_vehicles_count = obj.active_vehicles_count + 1;
obj.vehicles(1).lane = 1;
obj.vehicles(1).position = 3;
obj.vehicles(1).velocity = 3;
obj.vehicles(2).lane = 2;
obj.vehicles(2).position = 3;
obj.vehicles(2).velocity = 3;
end
클래스 정의, 나는 예상대로 출력을 볼 수 없습니다 (이다 vehicles_handle.vehicles (1)), 나는 그들에게 참조 차량 (1)의 특성을 0으로한다. 상황이 바뀌 었습니다. 물론 VehicleHandle이라는 함수에 넣었을 때이 방법으로 차량 생성을 처리하고 싶습니다.
이 코드가이 코드를 처리하는 가장 효율적인 방법은 아닐지도 모르지만 실제로이 클래스의 구조체를 통증없이 처리하는 방법에 대해 배우고 싶습니다. 모든 건설적인 의견과 도움을 미리 주셔서 감사합니다. 문제를 제거하기
고맙습니다. – mozcelikors