Trouble with Indexing and Parfor
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Jacob Mevorach
am 30 Mär. 2017
Kommentiert: Jacob Mevorach
am 11 Mai 2017
I've been trying to implement parfor in the following loop for a while but can't seem to find a way to get around the problem that parfor does not allow one to use indexes for variables that are not the loop variable. However given that the index in this case should be able to be sliced I'm wondering if there's a way I could implement parfor or maybe even spmd I'm not seeing.
function tracks_Out = updateAssignedTracks(tracks, centroids, bboxes, assignments)
tracks_Out=tracks;
numAssignedTracks = size(assignments, 1);
for i = 1:numAssignedTracks
trackIdx = assignments(i, 1);
detectionIdx = assignments(i, 2);
centroid = centroids(detectionIdx, :);
bbox = bboxes(detectionIdx, :);
% Correct the estimate of the object's location
% using the new detection.
correct(tracks_Out(trackIdx).kalmanFilter, centroid);
% Replace predicted bounding box with detected
% bounding box.
tracks_Out(trackIdx).bbox = bbox;
% Update track's age.
tracks_Out(trackIdx).age = tracks_Out(trackIdx).age + 1;
% Update visibility.
tracks_Out(trackIdx).totalVisibleCount = ...
tracks_Out(trackIdx).totalVisibleCount + 1;
tracks_Out(trackIdx).consecutiveInvisibleCount = 0;
end
end
I would greatly appreciate any help.
0 Kommentare
Akzeptierte Antwort
Ken
am 11 Mai 2017
The root cause of the error is that the indexing of the 'assignments' array is not 'fixed'. A requirement of sliced variables in parfor-loops is that the indexing expression must be the same for all occurrences. A few different approaches could solve the issue of different indexing expressions,e.g.,
trackIdx = assignments(i, 1);
detectionIdx = assignments(i, 2);
1. Split the 'assignments' array into two different arrays.
2. Reorganize the 'assignments' array into a cell array of pairs, e.g., trackIdx = assignments{i}(1), detectionIdx = assignments{i}(2)
3. Add a nested for-loop with an if-else statement.
for j=1:2
if mod(j,2) == 1
trackIdx = assignments(i,j)
else
detectionIdx = assignments(i,j)
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!