This should be easy (i hope), create area using coordinates
1 次查看(过去 30 天)
显示 更早的评论
Hi all,
I am new to MATLAB and creating a particle tracking model combined to a hydrodynamic model. I initially start by using a square utilizing xMIN xMAX, yMIN, yMAX. However, I have imported the Coordinates from a shape file from arcMAP 10.1 using a .txt file. My question is how can I possibly define the starting position of the particles within the boundaries of the area of the coordinates. i.e if i joined the dots together how do i put the particles within this area and give them a random position within this area.
heres the code upto the release point and random positon within the grid
%%gets the grid and bathymetry, only need it once
folder = 'U:\College of Natural Sciences\Research Data\mar1990\';
depthandgrid = ([folder,'mar90.00001.nc']); % Select file
ncid = netcdf.open(depthandgrid,'NC_NOWRITE'); % Opens file
depth = netcdf.getVar(ncid,0,'double'); % Depth
landsea = netcdf.getVar(ncid,1,'double'); % Border between land and sea
netcdf.close(ncid); % Closes netcdf
%%Irish Sea and POM variables
X1 = -9.0; X2 = -2.7; % X-axis
Y1 = 50.1; Y2 = 56.; % Y-axis
xspac = 1/30; % X-axis grid distances
yspac = 1/60; % Y-axis grid distances
long = X1: xspac: X2; % Long = x axis
lati = Y1: yspac: y2 % Lati = y axis
nt = 10272; % Number of time steps
nx = 190; ny = 354; nz = 21; % Irish sea grid dimensions
dt = 1800; % POM output time step
dx = 2000.; dy = 2000.; % Cell size (m)
start = 4000; % Starting iteration
finish = 4200; % Finishing iteration
np = 1000; % Number of particles released
%%Initial example release site:
xSMNRmin = 115*dx; xSMNRmax = 125*dx; ySMNRmin = 125*dy; ySMNRmax = 135*dy; zSMNRmin= 21; zSMNRmax = 21; % Gives start points in metres
%Loops for all particles to give a random position
for i=1:np;
x(i)=(rand*(xSMNRmax-xSMNRmin))+xSMNRmin; % Random place in the grid with the x direction
y(i)=(rand*(ySMNRmax-ySMNRmin))+ySMNRmin; % Random place in the grid with the y direction
thanks Hayden
2 个评论
Sara
2014-7-14
Do you mean that the coordinates you import from the shapefile do not describe a rectangle box, so you need a way to determine if a point is within an area of arbitrary shape?
Image Analyst
2014-7-14
What's wrong with using rand() like you did? It looks fine to me (other than missing the end statement).
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NetCDF 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!