Search code examples
matlabmatlab-figure

Construct a matrix in matlab from two arrays of points


I need to specify a set of points on the plane, for this I formed two vectors of the position of these points on the plane. Next, I created one matrix, where each row corresponds to one point (its two coordinates). As a result, all these points need to be located on the chart. I made such a matrix using several points as an example, but I need to significantly increase their number and it becomes unrealistic to manually write coordinates. How can you define such a matrix in a simpler way? Desirable without cycles

x = [1:3]'
y = [1:3]'
R = [x(1) y(1);
     x(2) y(1);
     x(3) y(1);
     x(1) y(2);
     x(2) y(2);
     x(3) y(2);
     x(1) y(3);
     x(2) y(3);
     x(3) y(3)]
 plot(R(:,1), R(:,2),'*','MarkerSize',40)

Solution

  • x = [1:3]';
    y = [1:3]';
    R = combvec(x',y')'
    
    R =
    
         1     1
         2     1
         3     1
         1     2
         2     2
         3     2
         1     3
         2     3
         3     3