How can i create a program that allows the user to enter in xy coordinates for the location of sprinklers, then calculates the water accumulation taking into account overlapping sprinklers and plots the water distribution?

1 view (last 30 days)
I am trying to create a program that a user can input sprinkler locations (x,y) and greenhouse dimensions and it will calculate the water coverage over the entire greenhouse. I understand logically how to do it but am having trouble programming it into MATLAB.
Steps:
  1. User inputs greenhouse width and length in feet
  2. User inputs the number of sprinklers
  3. User inputs x,y locations of the sprinklers in feet
  4. Assuming "x" is along the length and "y" is along the width, divide the greenhouse into 0.5 ft by 0.5 ft areas and calculate the distance of each sprinkler to each small segment of the greenhouse.
  5. Using a lookup table, calculate the amount of water that each sprinkler will contribute to each small segment of the greenhouse.
  6. Add all of the contributions from all of the sprinklers to each small segment.
  7. Plot out a 3D contour that shows the floor of the greenhouse and how much water fell in each area.
I figured out how to do steps 1 through 3 but am stuck on step 4. Any help you could give would be much appreciated. Thank you
  8 Comments
Jeff Chapin
Jeff Chapin on 22 Nov 2015
thank you...that worked for the axes and figure. Any ideas on how to do #4 above. Once I have the coordinates of the sprinkler locations then I need to divide the green house into a grid of points and calculate the distance from each of the points to each of the sprinklers.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 21 Nov 2015
You'd need to create the axes in advance of using ginput(). Use xlim() and ylim() to set up the axes limits that you want.
  7 Comments
Image Analyst
Image Analyst on 1 Dec 2015
If you ahve the Statistics and Machine Learning Toolbox, pdist2() might be easier. I think it's
distances = pdist2(xy1, xy2);
where xy1 is an M by 2 list of (x,y) coordinates for one set and xy2 is for the other set, but I think you have just one set so you'd use
distance = pdist2(xy, xy);
See if that works. If it does not then you'll just have to use the intuitive, brute force method of the for loops (can you really not figure out how to do that?)
Walter Roberson
Walter Roberson on 1 Dec 2015
With SprinklerLocation a 2 column matrix, and X and Y being arrays of coordinates for the grid centres,
distances = sqrt(sum(bsxfun(@minus, [X(:), Y(:)], SprinklerLocation),2));

Sign in to comment.

Categories

Find more on Agriculture in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!