Slope of a plotted function in a specified point.
    6 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Hi,
I've currently plotted an array signal that displays x and F(x) (not in a continuous manner but in a discreet one as it's an array). The signal plot is shown below. 
My question is if there is a way to find out the slope of a point in the plot or if you can somehow get a slope from two close points on the plot, so I can then calculate m (slope constant). I need this in order to find out the transfere function of the signal.
Thank you very much in advance.
Yours faithfully.
Edward.

0 件のコメント
回答 (1 件)
  Star Strider
      
      
 2020 年 11 月 15 日
        It would be easier to have your data.  
Try this: 
xv = linspace(0, 5);                                                        % Create Data
yv = sin(2*pi*xv*2.5);                                                      % Create Data
slopefcn = @(xsel,xv,yv) interp1(xv, gradient(yv)./gradient(xv), xsel);     % Interpolate Slope At ‘xsel’
yval = @(xsel,xv,yv) interp1(xv, yv, xsel);                                 % Interpolate ‘yval’ At ‘xsel’
xsel = 2.35;                                                                % Selected ‘X’ Value
ysel = yval(xsel,xv,yv);                                                    % Corresponding ‘Y’ Value
m = slopefcn(xsel, xv, yv);                                                 % Calculate Slope
b = ysel - m*xsel;                                                          % Calculate Y-Intercept (To Draw Line)
calcLine = m*(xsel+[-1 1]*0.05) + b;                                        % Calculate Line For Plot
figure
plot(xv, yv)
hold on
plot(xsel, ysel, '+r')                                                      % Plot Point (Demonstration Only)
plot(xsel+[-1 1]*0.05, calcLine, '-r')                                      % Plot Line (Demonstration Only)
hold off
My code calculates the slope at ‘xsel’ and then plots a line using it in order to demonstrate that it works.  That part of the code is not necessary if you do not want to plot a line at the ‘xsel’ point.  The data do not need to be regularly-sampled for it to work.  
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!