How do I generate distances between a varying object within a grid and 5 fixed locations.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Fun Dan
el 24 de Abr. de 2015
Respondida: Fun Dan
el 25 de Abr. de 2015
How do I generate a code that would calculate the distances of the 4 stations and EU to the DC for every given location of the DC within the grid defined below . That is, for every time the DC is moved around within the grid, I want the corresponding distances.
% Grid Definition of the Distribution Center (DC)
n = 10; % Number of grids in the x-direction
x = 50; % Dimension of a grid in the x-direction
k = 8; % Number of grids in the y-direction
y = 50; % Dimension of a grid in the x-direction
% Location of stations (coordinates)
S1 = [100 20];
S2 = [20 150];
S3 = [50 450];
S4 = [150 450];
% Location of the End User
EU = [7000 200];
I am trying to cost all the options so I can get the cheapest layout.
I have attached a sketch of the layout for better understanding.
Thank you.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149458/image.jpeg)
0 comentarios
Respuesta aceptada
Joseph Cheng
el 24 de Abr. de 2015
so you can create x and y pairs using meshgrid()
Gx = [50:50:500];
Gy = [50:50:400];
[Gx Gy] = meshgrid(Gx,Gy);
then knowing your static locations and what the distance formula is [sqrt((x2-x1)^2+(y2-y1)^2)] or using the hypot() function you can calculate the distances between each station DC and EU. you might be able to use the function pdist() but i haven't used it in a while.
0 comentarios
Más respuestas (1)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!