Obtain each value from XY graph in Simulink - simulink

how can I obtain the value from XY graph in Simulink? I just wanted to make sure I did the correct thing and obtained the correct value.

Related

How to obtain an equation for a line fitted to data

I am trying to obtain an equation for a function fitted to some histogram data, I was thinking of trying to do this by fitting a rational function as the data doesn't resemble any distribution recognisable by myself.
The data is experimental, and I want to be able to generate a random number according to its distribution. Hence I am hoping to be able to fit it to some sort of PDF from which I can obtain a CDF, which can be rearranged to a function into which a uniformly distributed random number between 0 and 1 can be substituted in order to obtain the desired result.
I have attempted to use the histfit function, which has worked but I couldn't figure out how to obtain an equation for the curve it fitted. Is there something stupid I have missed?
Update: I have discovered the function rationalfit, however I am struggling to figure out what the inputs need to be.
Further Update: Upon exploring the histfit command further I have discovered the option to fit it to a kernal, the figure for which looks promising, however I am only able to obtain a set of x and y values for the curve, not its equation as a I wanted.
From the documentation on histfit:
Algorithms
histfit uses fitdist to fit a distribution to data. Use fitdist
to obtain parameters used in fitting.
So the answer to your question is to use fitdist to get the parameters you're after. Here's the example from the documentation:
rng default; % For reproducibility
r = normrnd(10,1,100,1);
histfit(r)
pd = fitdist(r,'Normal')
pd =
NormalDistribution
Normal distribution
mu = 10.1231 [9.89244, 10.3537]
sigma = 1.1624 [1.02059, 1.35033]

Are MATLAB's lsim outputs derivatives or the state vector?

I'm trying to do a simulation of a 2-body mass-spring-damper. I've set up a state-space model that I'm pretty confident in and set an input of a displacement and velocity at the base in just one degree of freedom. Upon getting my outputs, I expected that the output vector would just be the state vector at each time step. However, when plotting the output vector corresponding to displacement for each mass in the vertical direction (the input direction), it looked much more like a velocity (0 at the extrema of the input). The plots are shown below:
When I integrated the top 2 plots, I got the following:
Now, I obviously can just accept the outputs as they are and assume I am right in my understanding. But, I want to be sure. From the documentation page:
lsim(___) also returns the time vector t used for simulation and the
state trajectories x (for state-space models only)
I'm just hoping to find out whether or not I am correct in that the output matrix columns correspond to the history of the state derivatives before I go base an analysis on a bad assumption.
I figured it out. My B-matrix expected [derivative, state,...] but I had them in the opposite order.

How can I extract data in a vector from semilogx figure?

How can I extract data in a vector from semilogx figure?
I am using bode plot to identify a system transfer function so I need the two vectors coming from semilogx graph to compare slope and identify system from approximate solution.
Is there any other method to do this identification?I wanna get the slope of this figure so i need xy data from this figure
Why are you asking specifically semilogx plot? When you get the data from a figure, you access the data directly as in here. What am I missing here?
hc=get(gca,'children');
data=get(hc,{'xdata','ydata'});
x=data{1};
y=data{2};

MATLAB: Gaussian RV

So... I am working on part b and I haven no idea what this question is asking me to do. Does it want me to plot the actual Q(x) equation graph with part a graphs?
It appears as if you need to plot the pdf(x) and cdf(x) and compare to the estimated pdf and cdf you obtained for the different values of t.

Expectation values in MATLAB

I have a 3D data set representing a grid of photosensors which unfortunately were not steady during use. I have estimated the pdf for the motion of the detector and I want to find the expectation value for each sensor. As I don't want to reflect my pdf (i.e. I want f(t) not f(t-tau)) I don't think I can use the matlab convolve function. Is there a function that will do what I want or should I just get on with it? I've found movavg but it seems to do something else or maybe I just haven't followed it correctly.
Also, as I'm faily new to matlab, from C, I tend to use for loops which I'm aware is not the way to use Matlab. Is there an easy way to convert my 1-D pdf to a 3D matrix that will only operate in one axis (z in this case). Something like repmat(i, j, pdf).
Thanks
The expected value of a pdf is the integral over the product of the grid values and the pdf values at the corresponding grid points.
To integrate over a 3D-Grid, use the Matlab function triplequad (doc). As an example, let us compute the expected x value:
expectedx = triplequad(pdfxfun,xmin,xmax,ymin,ymax,zmin,zmax)
pdfxfun in this call must be a function handle which for any (x,y,z) point it receives should return the product of the pdf value at that point and x. In your case, this could probably be achieved by interpolation over your grid data. I don't know a 3D-interpolation function in Matlab, so probably you have to work on this for yourself. Roughly, what you would do is:
function pdfvalue = pdfinterpolation(x,y,z,Xgrid,Ygrid,Zgrid,pdfdata)
% compute interpolated pdfvalue at (x,y,z) from griddata and pdfdata
Then, pdfxfun above can be defined as anonymous function in the call to triplequad:
pdfxfun = #(x,y,z) x*pdfinterpolation(x,y,z,myxgrid,myygrid,myzgrid,pdfdata)
expectedx = triplequad(pdfxfun,xmin,xmax,ymin,ymax,zmin,zmax)