How to calculate the slope of a curve
146 views (last 30 days)
Show older comments
How can I determine the slope of this curve. Thanks for help!
Best regards
2 Comments
Stephen23
on 29 Jul 2015
Edited: Stephen23
on 29 Jul 2015
Where did you get the image from: is it generated from some code in MATLAB, or plotted numeric data, or did someone just email you an image file?
All of these are valid ways of obtaining the curve, but they require different solutions. So you need to help us by actually giving some information about the curve: How is it defined?
Answers (1)
Star Strider
on 29 Jul 2015
The .fig file has the requisite data, so specific code is possible. The easy way of course would be simply to calculate the analytic derivative and write a function to produce it.
This will calculate and plot it using the gradient function. Experiment with it to get the result you want:
DF = openfig('AB ABOULOUARD fig.fig');
H1 = get(gca, 'Children'); % Get Handle To Data In ‘.fig’ File
x = get(H1, 'XData'); % Get ‘x’ Data
y = get(H1, 'YData'); % Get ‘y’ Data
dx = mean(diff(x)); % Find Mean Differece In ‘x’ Values
dy = gradient(y,dx); % Calculate Slope Of Data
xq = find((x >= 0.275) & (x <= 0.325)); % Index Of Area Of Interest ‘x’ Values
slope_x = x(xq); % ‘Slope’ ‘x’ Values Of Interest
slope_y = dy(xq); % ‘Slope’ ‘y’ Values Of Interest
figure(2)
plot(x, dy, '-g')
hold on
plot(slope_x, slope_y, '-r', 'LineWidth',1)
hold off
grid
legend('Slope Of All Data', 'Slope Of Data In Region Of Interest', 'Location','W')
4 Comments
Star Strider
on 26 Aug 2021
Yes.
There will of course be more than one value unless the slope is constant (and the relation therefore linear in that region).
.
See Also
Categories
Find more on Loops and Conditional Statements 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!