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)
Show older comments
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:
- User inputs greenhouse width and length in feet
- User inputs the number of sprinklers
- User inputs x,y locations of the sprinklers in feet
- 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.
- Using a lookup table, calculate the amount of water that each sprinkler will contribute to each small segment of the greenhouse.
- Add all of the contributions from all of the sprinklers to each small segment.
- 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
Walter Roberson
on 22 Nov 2015
round(x*2)/2 gets you x to the nearest 0.5 .
Once you have the coordinates see pdist()
Answers (1)
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
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
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));
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!