Is it possible to use InterX on multiple lines at once?

1 次查看(过去 30 天)
I have bathymetric data at 3 cross sections and want to find the points of intersection of each of these curves with numerous lines representing water level [see image for an idea of what I'm talking about]
Is it possible to use InterX, with proper formatting of the data, to calculate the points of interception of all the lines in one go. Or do I have to do it for each water level on each cross section separately (not prefereable given 3 cross sections and 23 water levels!) ?
Many thanks!
  1 个评论
Dom Smith
Dom Smith 2017-1-27
As a further to this question, how would you go about calculating the area between line and a particular curve?
I presume that, as there is no point at the intersection of line and curve, it must be necassary to interpolate, or use the coordinates of intersection found from my previous question and somehow input these into trapz to find the area. But I cannot think of a fluent way of coding this. Thanks again for any help!

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2017-1-27
The file exchange contribution InterX only works between two curves at a time, each specified as two rows with x coordinates in the top row and y coordinates in the bottom row.
If you were to give the water level in one of the two, and were to put the curves all together in the other one, horzcat together, then because all of the points of intersection are looked for, that might work. You might have to filter out some spurious intersections at the junction point between the spliced curves.
  4 个评论
Walter Roberson
Walter Roberson 2017-1-27
Your image shows a number of discontinuous line segments that represent water level. For the purpose of analysis can they be treated as continuous lines of constant value? If so then there are faster ways to search.
mask = water_height(row,:) >= a_water_level;
goes_above = strfind([0 mask 0], [0 1]);
goes_below = strfind([0 mask 0], [1 0]) - 1;
goes_above(K) will be a location at which the water height rises from below the threshold to above, and goes_below(K) will be a location at which that same stretch of water height goes from above or at the threshold to below it.
This code is able to isolate locations where the water rises to the level for only a single point and then falls again: in such a case the location pair will be equal.
Unfortunately, it is difficult to vectorize finding runs this way, as there can be different numbers of matches for different heights.
In the more restricted case where you do not need explicit information about the runs, just the locations of intersections, then
mask = bsxfun(@le, all_water_levels(:), water_height(row,:));
z = zeros(size(mask, 1), 1);
bmask = [z, mask, z];
goes_above_mask = ~bmask(:, 1:end-1) & bmask(:, 2:end);
goes_below_mask = bmask(:, 1:end-1) & ~bmask(:, 2:end);
goes_above_locs = goes_above_mask .* repmat( 1:size(goes_above_mask, 2), size(goes_above_mask, 1), 1);
goes_below_locs = goes_below_mask .* repmat( 0:size(goes_above_mask, 2)-1, size(goes_above_mask, 1), 1);
Now each row of goes_above_locs and goes_below_locs is associated with a different probe water height. Along the row, the non-zero entries of goes_above_locs give indices into the row of water height information at which the water went from below the probe level to above it, and the non-zero entries of goes_below_locs give indices into the row of water height information at which the water went from above the probe level to below it. As all of the probe water levels are tested simultaneously, this is a more vectorized version. However, selecting the non-zero entries in each row cannot exactly be vectorized. You could, though:
arrayfun(@(IDX) nonzeros(goes_above_locs(IDX,:)), 1:size(goes_above_locs,1), 'uniform', 0)
though if you are going to do that then you might as well not compute the _locs arrays and instead use
arrayfun(@(IDX) find(goes_above_mask(IDX,:)), 1:size(goes_above_mask,1), 'uniform', 0)
The code computing goes_above_locs and goes_below_locs is a vectorized form of find() along rows, except that it leaves the non-matching entries in the array as 0.
Dom Smith
Dom Smith 2017-1-29
Thanks so much for the detail! I'll give it a test run and see how I fair

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by