How to avoid for loops while storing cell indices of a Grid?

1 view (last 30 days)
Hi,
I am working on an object tracking project in an automotive environment. I am creating a Grid in Matlab which rotates in every measurement frame according to yaw rate of the ego vehicle. So, for every frame, I have to store the indices of all the grid cells in an array so that I can use that array later to find out that which detections are lying in which cells. The piece of code that does this index storing work for me is:
cellIndicesCtr = 1;
for i=1:size(x2,1)-1
for j=1:size(x2,2)-1
cellsIndices_local{cellIndicesCtr,1} = [x2(i,j) x2(i,j+1) x2(i+1,j+1) x2(i+1,j) x2(i,j)];
cellsIndices_local{cellIndicesCtr,2} = [y2(i,j) y2(i,j+1) y2(i+1,j+1) y2(i+1,j) y2(i,j)];
cellIndicesCtr = cellIndicesCtr + 1;
end
end
x2 are y2 are the arrays with the x- and y-coordinates of the rotated grid respectively. My question is: Can I do this without using the for loops? Don't bother about the order in which I am storing the indices. That's for plotting purposes. I am just concerned with getting rid of for loops. Any help in this regard would be highly appreciated. Thanks!

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!