I have an xy coordinates positions (100x2) and another z vector (100x1) with values corresponding to each xy coordinate. How can I make a matrix of the coordinates with the position of each coordinate having the corresponding z value? Thanks!
% Setup / initialization. % Start out matrix as zeros. m = zeros(20,10); % Generate 100 random coordinates. xy = int32(randi(10, 100, 2)); % Get matrix values for those x,y locations z = randi(255, 100, 1); % 100 values.
% Now, do what the poster, John, wants to do. % Assign the z values to the (x,y) coordinates at the corresponding row. % E.g. m at (x(1), y(1)) will have a value of z(1). % m at (x(2), y(2)) will have a value of z(2). And so on. indexes = sub2ind([20, 10], xy(:,1), xy(:,2)) m(indexes) = z