I am using the queue counter, I have put the queue counter in VISSIM GUI and saved & enabled it but while i am coding it in MATLAB the results are showing NaN, Why is it so

조회 수: 8 (최근 30일)
%Link Numbers
Link_Num_1=Link_i.ItemByKey(5);
Link_Num_2=Link_i.ItemByKey(7);
Link_Num_3=Link_i.ItemByKey(13);
Link_Num_4=Link_i.ItemByKey(23);
simulation_duration = 7200; % Total simulation time in seconds
interval = 1; % Collect queue length every 120 seconds
num_intervals = simulation_duration / interval; % Number of 120-second intervals (60)
% Initialize matrix for queue lengths (60 rows)
queue_lengths = zeros(num_intervals, 1);
% Get queue counter
queue_counters_1 = Link_Num_1.QueueCounters.GetAll;
qc1 = queue_counters_1{1}; % First queue counter
% Display queue counter info
disp(['Number of queue counters: ', num2str(length(queue_counters_1))]);
disp(['Queue Counter Object: ', class(qc1)]);
disp(['Queue Counter Name: ', qc1.get('AttValue', 'Name')]);
% Run simulation and collect queue length every 120 seconds
interval_idx = 0; % Counter for interval index
for t = 1:interval:simulation_duration
% Run simulation for 120 seconds
for step = 1:interval
sim.RunSingleStep;
end
% Increment interval index
interval_idx = interval_idx + 1;
% Get queue length
queue_length = qc1.get('AttValue', 'QLen(Current, Last)');
if isnan(queue_length)
queue_length = 0; % Replace NaN with 0
end
queue_lengths(interval_idx, 1) = queue_length;
% Display queue length for this interval
disp(['Time ', num2str(t), 's: Queue Length = ', num2str(queue_length)]);
end
disp('Queue Length collection complete.');

답변 (1개)

Kautuk Raj
Kautuk Raj 2025년 6월 5일
I suspect you are getting NaN because the queue counter might not be properly set up or accessed. Could you try these quick fixes?
  1. Run a step before reading: Add sim.RunSingleStep; before the loop to initialize the simulation.
  2. Check if queue counter exists: Make sure queue_counters_1 is not empty.
  3. Use correct attribute: Try 'QLen(Current)' instead of 'QLen(Current, Last)'.
  4. Ensure it is placed correctly: In VISSIM, confirm the queue counter is on the right link/lane and enabled.
I hope one of the above troubleshooting steps will help resolve the issue.

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by