Graphical construction (max, min, tangent line in a point) from simulink scope / multiplot graph

38 views (last 30 days)
Hi all, i've the graph from a simulink simulation in a multiplot graph;
then i need to find the point of maximum slope of that graph (along with its x, y coordinates), in that point i need to plot the tangent line to the graph, and then plot the intersections with x axis and the extrapolation from max value of graph of this tangent line. To make simpler to explain i've an image of what i would to obtain:
I've already tried to send graph data to workspace, but then plotting it i lose the time x axis...
Any help would be very appreciated.

Accepted Answer

Paulo Silva
Paulo Silva on 28 Jul 2011
Using the To Workspace block
  1. Insert the block in your simulation and connect it to the desired output
  2. Open the To Workspace parameters and change the save format to Structure with time
Do the simulation and the data appears on the workspace, you can use it and plot it like this
plot(simout.time,simout.signals.values)
  2 Comments
Michele
Michele on 28 Jul 2011
Thanks Paulo Silva, your reply has helped me to plot with right x-axis; now can you be so kindly to show me how to obtain the maximum slope point of the curve and then drawing the tangent curve at the plot in that point?
Paulo Silva
Paulo Silva on 28 Jul 2011
Michele we expect you and everyone else to show some effort at solving the problems, we are here to help at specific questions, not to do all your work.
Here's more code but please try to understand it to finish what you want, the only thing that's missing is the line, the code gives you the slope and you can easily find the maximum slope.
si=simout.signals.values;
st=simout.time;
cla;hold on
plot(st,si)
d=diff(si)./diff(st); %d is the slope of the signal
[C,I]=max(d); %find maximum of the slope C and the index I where the slope is
plot(st(1:end-1),d,'r')
legend('signal','slope')

Sign in to comment.

More Answers (2)

Michele
Michele on 29 Jul 2011
Thank you vary much, Paulo, with our right and precious directions i'm almost done:
now my last problem is to find point of curve such as
max = max of curve t1 = .268*max t2 = .632*max
i've tryed with find(si == .268*max) but it returns an empty matrix... Thanks again.
  3 Comments
Michele
Michele on 29 Jul 2011
Thanks,
the first answer finds the first element in vector which is >= st1; and it works.
Just for curiosity, i've tried with interp1, but it "interpolates to find yi, the values of the underlying function Y at the points in the vector or array xi. "
infact by doing
yi = interp1(st,si,50,'spline')
it finds the correct value of function at x=50;
but i need the inverse compute: given yi, i would to find the xi, in this case can i also use interp1?

Sign in to comment.


Nelis Vandermeiren
Nelis Vandermeiren on 30 Dec 2011
Hello
I need to do the same thing, but here is my question: How can you plot the tangent line on the (step-response) graphic where the slope is max? and how to add those intersection points?

Community Treasure Hunt

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

Start Hunting!