MATLAB: Creating a n*2 array from a variable in workspace

mathematicsMATLABstatisticsworkspace

I have a variable on my workspace, in which i have n*2 elements ( 'n' rows and 2 columns). I wanna create an array to do some computation on all the elemental pairs of that variable, such that x1,y1… How can i do that ???

Best Answer

Try this and then adapt as needed:
% Creating bounding box at any given x,y
grayImage = imread('moon.tif');
[rows, columns, numberOfColorChannels] = size(grayImage)
imshow(grayImage);
boxHalfWidth = 40; %
xy = boxHalfWidth + rand(10, 2) * (rows - 2 * boxHalfWidth);
for k = 1 : size(xy, 1)
x = xy(k, 1);
y = xy(k, 2);
hold on
plot(x, y, 'r+', 'MarkerSize', 25)
boxXStart = x-boxHalfWidth;
boxYStart = y-boxHalfWidth;
boxWidth = 2 * boxHalfWidth;
boxHeight = 2 * boxHalfWidth;
rectangle('Position',[boxXStart boxYStart boxWidth boxHeight], 'EdgeColor', 'r')
end
0001 Screenshot.png