MATLAB: I need a help on matlab code for a condition of 1 user equipment (UE) moves from source cell to target cell which is it starts at any coordinate (from source cell) and ends at the end border(of target cell).

handoverhexagonmovement 1 ue from source cell to target cellsource celltarget celluser equipment (ue)

I only have code for creating one cell (but i need 2 cells). Here are the code:
% Program1 (Single Hexagonal Cell)
% Draw a hexagonal cell
function Drawhex1(x_init,y_init,cell_radius)
x_init = 0;%Set initial x-coordinate to 0
y_init = 0;%Set initial y-coordinate to 0
cell_radius = 1;%Set cell radius equal to 1km
% Location of 6 edges in a hexagonal cell
bs_xloc(1)= x_init+cell_radius;
bs_xloc(2)= x_init+cell_radius*cos(pi/3);
bs_xloc(3)= x_init+cell_radius*cos(2*pi/3);
bs_xloc(4)= x_init-cell_radius;
bs_xloc(5)= x_init+cell_radius*cos(4*pi/3);
bs_xloc(6)= x_init+cell_radius*cos(5*pi/3);
bs_xloc(7)= x_init+cell_radius;
bs_yloc(1)= y_init;
bs_yloc(2)= y_init+cell_radius*sin(pi/3);
bs_yloc(3)= y_init+cell_radius*sin(pi/3);
bs_yloc(4)= y_init;
bs_yloc(5)= y_init+cell_radius*sin(4*pi/3);
bs_yloc(6)= y_init+cell_radius*sin(4*pi/3);
bs_yloc(7)= y_init;
bs_pos=[bs_xloc' bs_yloc'];%location of all 6 edges
plot(bs_pos(:,1),bs_pos(:,2),x_init,y_init,'^r');%Plot from 1 edge to another
hold on
% draw handover boundary
circle=rsmak('circle',0.8134,[x_init,y_init]);
fnplt (circle)
hold off
Can someone help me please? Thank you in advanced.

Best Answer

Oh well, you did clean it up, so that now we can actually see what you are doing.
First of all, I'd start by pointing out that you are using MATLAB as if it is a spreadsheet or some very basic language. Instead, start thinking in terms of vectors, arrays, etc.
So, assuming that xy_init is a ROW vector of length 2, and that you are using the most recent release of MATLAB...
function Drawhex1(xy_init,cell_radius)
% polar coordinates
theta = linspace(0,2*pi,7).';
% x = r*cos(theta)+x0, y = r*sin(theta)+y0
bs_pos = cell_radius*[cos(theta),sin(theta)] + xy_init;
plot(bs_pos(:,1),bs_pos(:,2),'-r');
Note that if you are using release R2016a or earlier, then you will need to use bsxfun for the line that created bs_pos.
If you want to plot a second hex, this is simple. Just use hold on after the first call. That will cause MATLAB to plot on the current set of axes, rather than creating a new figure for each hex. So the only problem then will be to decide on a new center for each hex, a simple problem of geometry.
Note that eventually, you will be wanting to create more complex structures in a rather large hexagonal lattice. You can certainly do this too, but then you will need a more sophisticated way to handle the polygon creation and storage thereof.