Finding average slope without losing steep slopes

32 visualizaciones (últimos 30 días)
Derrick Vaughn
Derrick Vaughn el 3 de Oct. de 2020
Comentada: Star Strider el 3 de Oct. de 2020
Hi everyone, I am plotting river profiles with distance upstream along the x and elevation/height along the y. I am then wanting to take the average slope change within the river profile; however, many of the profiles I am plotting include points where distance remains the same but elevation increases (see image below for an example), leading to slope values of infinity. I previously removed these infinity values to calculate average slope but realized by removing them, I'm skewing the average slope towards the lower slope values, which impacts my end goal. Does anyone have any suggestions on how I can calculate average slope while also accounting for these steep slopes.
Example of data:
ch_height =
Columns 1 through 20
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
ch_length =
Columns 1 through 20
0 0 0 0 0.4612 0.9225 0.9225 0.9225 1.5748 2.2271 3.5317 3.5317 3.5317 3.9929 3.9929 4.4542 5.5677 5.5677 5.5677 5.5677
Plotted Profile (not concerned about data below sea-level in this example):
Portion of Code related to question:
slope=diff(ch_height)./diff(ch_len);
slope=slope(slope~=0 & isfinite(slope)); % this is where I previously removed infinity values for the steep slopes
I was thinking of possibly connecting the last point of the infinie slope to the previous point where the ch_len is of a different value. For example, where ch_len = 0, connecting the point (0,0) with the point (0.4612, 4). If this is the best option, how could I code this so that it applies to each of the infinite slopes?
Thanks in advance!

Respuestas (1)

Star Strider
Star Strider el 3 de Oct. de 2020
I have no idea whatt you actually want to do. One option is to simply do a linear regression on the entire data:
ch_height = [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19];
ch_length = [0 0 0 0 0.4612 0.9225 0.9225 0.9225 1.5748 2.2271 3.5317 3.5317 3.5317 3.9929 3.9929 4.4542 5.5677 5.5677 5.5677 5.5677];
B = [ch_length(:) ones(size(ch_length(:)))] \ ch_height(:);
Slope = B(1)
Intercept = B(2)
X_Intercept = -B(2)/B(1)
figure
plot(ch_length, ch_height, '-p')
hold on
plot(ch_length, [ch_length(:) ones(size(ch_length(:)))]*B, '--r')
hold off
grid
xlabel('Length')
ylabel('Height')
legend('Data','Linear Regression', 'Location','SE')
.
  2 comentarios
Derrick Vaughn
Derrick Vaughn el 3 de Oct. de 2020
Hi, thanks for your comment and I'm sorry I didn't quite explain everything. While the linear regression does help with finding the overall average slope of the profile, there are times further in this project where I would want to find the average slope of portions of the profile (say looking at the slope at the upper 10 points of the profile vs. the slope at the lower 10 points of the profile). Could the linear regression you provided above be modified so that I'm looking at just portions of the profile and applying the slope of that one portion to the entire profile? For example, if I would want the use the average slope of the the higher 10 points (10-19m) and apply that slope to the entire profile.
Star Strider
Star Strider el 3 de Oct. de 2020
This is the best I can come up with:
[TF,m,b] = ischange(ch_length,'linear', 'Threshold',0.001); % Change Points, Slope At Every Point
[um,~,idx] = unique(m, 'stable'); % Unique Slope Values
meanm = accumarray(idx, (1:numel(idx)).', [], @(x)mean(m(x))); % Means Of Unique Slope Values
meanm = meanm(meanm>1e-3) % Means Of Unique Slope Values (Omitting ‘Steps’)
The ischange function calculates the slopes and intercepts at every point of the data, then the accumarray call averages those that unique identifies as being the same. (You could also use uniquetol, however uniquetol sorts the outputs iin ascending order. Specifying 'stable' with unique — not an option with uniquetol — preserves the original ordering.)
Here, it identified and calculated:
meanm =
0.4612
0.6523
1.1135
With different or more extensive data, it can likely do more accurate calculations.

Iniciar sesión para comentar.

Categorías

Más información sobre Scatter Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by