How to create an equally spaced 1D array?
Afficher commentaires plus anciens
I have two vectors, x and y, of the same length (more or less 2600x1 double). For each element x, a corresponding element y is acquired. x is a vector of points (1,2,3,4...), y contains the corresponding values, which describe a certain function. The problem arises because of the way I acquire these data; the x vector is built from a moving translation motor: for each step of the motor, a new point is recorded. For example, when the motor moves a 1 mm step, I acquire the first element of x, i.e. 1, and the corresponding element y (it doesn't matter what y is, but it depends on the position of the motor too). After another step of 1 mm, I record the second element of x (i.e. 2) with the corresponding element (that is the second element of y) and so on. The problem is that the scanning is actually irregular: the motor doesn't move on perfectly regular steps of 1 mm, but sometimes for example 0.8 mm, 0.9 mm or 1.1 mm (also in this case the x vector records points separated by one - 1,2,3,4,5...- because a new element of x is generated for any movement of the motor, of whatever step). I need to build an x vector, and the corresponding y vector, *as if I had a perfectly regular scanning motor of equally spaced steps . How can I do this? Shall I have to correct the x vector by creating an equally space vector? I need also a corresponding y vector, so also the y vector must be corrected in function of the x one. I know it's not trivial, if you want more details ask me. Thanks
Réponse acceptée
Plus de réponses (1)
dpb
le 28 Nov 2013
Create a new x set of points however desired--a couple of possible choices would be N points between the first and last actual points, alternatively, fix from some x0 to xN at whatever you wish the endpoints to be. You may or may not want to extrapolate to get there, your choice
x1=linspace(x(1),x(end),nPts); % This is first alternative
y1=interp1(x,y,x1); % interpolate to the new x1 points
doc interp1 % for more details, options on extrapolation, interpolation type, etc., ...
2 commentaires
aurc89
le 29 Nov 2013
OK, but that certainly wasn't clear originally (to me, at least... :) )
Anyway, looking at your plots --
a) is 'x' known at any one (or more) point(s) at all? IOW, is there at least an origin and perhaps and endpoint that can be considered accurate?
b) is it to be assumed from the characteristic shape of the red curve that the actual response is to be linear?
Depending on the answers to the above, there are possibly some useful boundary conditions that can be used to aid in a solution similar to that proposed by Roger.
Also, what's known about the characteristics of the motor movement? Is it that the the motor moves at fixed speed and the sampling is simply asynchronous giving rise to the difference in actual positions or what? These kinds of ancillary pieces of info may also be helpful in modeling the output (I'm thinking "Kalman filter" maybe???)
Catégories
En savoir plus sur Electromechanical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
