This function is shown below, along with the relationship between vectors x, Y, xi, and yi. It finds values at intermediate points, of a one-dimensional function that underlies the data. The interp1 command interpolates between data points. Returns the scalar extrapval for out of range values. Uses the specified method to perform extrapolation for out of range values. For all other methods, interp1 performs extrapolation for out of range values. If Y is a matrix, then the interpolation is performed for each column of Y and yi is length(xi)-by- size(Y,2).Īssumes that x = 1:N, where N is the length of Y for vector Y, or size(Y,1) for matrix Y.įor the 'nearest', 'linear', and 'v5cubic' methods, interp1(x,Y,xi,method) returns NaN for any element of xi that is outside the interval spanned by x. The vector x specifies the points at which the data Y is given. Returns vector yi containing elements corresponding to the elements of xi and determined by interpolation within vectors x and Y. One-dimensional data interpolation (table lookup) In fact, if I was trying to use my straightline function with some other code that required lines to be defined by slope and intercept first, and then the abscissa, I can easily create a new interface for the line.Interp1 (MATLAB Functions) MATLAB Function Reference I could also use it to create a function of just slope and intercept, suitable for create line segments for different parameters at a later time. In the first case, I turned my function of 3 variables into a function of one variable, with preset parameters. Using the same original function definition for straightline, I am able to mold the function for different purposes. Newline2 = straightline(X, slp(2), intcpt(2)) Īnonymous Functions Allow Interface Flexibility Newline1 = straightline(X, slp(1), intcpt(1)) I can even get the values put into a slopeIntercept = straightline(data, slope, intercept) In that case, with data supplied, I can derive such a function from straightline. Perhaps I instead want a function of the slope and intercept only. Now compare estimates for slope and intercept to original values. Now I want slope and intercept to be my independent variables. m = 2 ĭata = straightline(t,m,b) + 0.2*randn(size(t)) And we would like to estimate the slope and intercept values. Now suppose we have data, based on this line segment, that has some noise. myarea = integral(myline, lowerlimit, upperlimit) Use this new function, myline, as the integrand. lowerlimit = 2 Ĭreate a function representing my particular line segment, by fixing those slope and intercept values, and creating a new function from the original one. Since the function integral requires the integrand to be a function of one variable only, we can use the anonymous function myline, defined below, to create just such a representation. Now let's find the area under a segment of this line, between two points. Now I can evaluate my function when I create the plot. I start by defining the slope and intercept values. straightline = slope*X + interceptįirst let's choose a particular straight line segment. Here's a very general way I can write the code meant to generate points on a straight line. Have You Used Anonymous Functions to Alter the Interface?.Anonymous Functions Allow Interface Flexibility.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |