Interpolating vectors at specific points
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello all,
I am trying to do some interpolation with 3 column vectors. The first vector v, is a velocity column vector. The next 2 vectors are the x and y coordinates corresponding to that velocity. I am trying to interpolate the velocity vector where it changes from positive to negative and return the corresponding x and y coordinates. I will illustrate this below the best I can.
V=[.8;1;.8;.3;-.3;-.8;-1]
x=[1;.8;.5;.4;.3;.2;.1]
y=[1;.5;.2;-.4;-.5;-.6;-.7]
From these 3 column vectors I would like to find x and y at V=0. After they are found I would like to insert them back into the vectors at there respective positions. So for velocity a 0 would be inserted between the change from positive to negative:
V=[.8;1;.8;.3;*|0|*;-.3;-.8;-1]
Then the x and y points corresponding to V=0 would be put back in the x and y column vectors at the right position.
x=[1;.8;.5;.4;|*.35*|;.3;.2;.1]
y=[1;.5;.2;-.4;*|-4.5|*;-.5;-.6;-.7]
The numbers I inserted are just to show how it would work and may not be the correct interpolated values.
0 Kommentare
Antworten (1)
Sven
am 15 Sep. 2013
Hi Christopher, here's a solution that does the job. If you can guarantee that you only have one crossing in your vector V, then you don't need the loop (or the break command).
V = [.8;1;.8;.3;-.3;-.8;-1];
x = [1;.8;.5;.4;.3;.2;.1];
y = [1;.5;.2;-.4;-.5;-.6;-.7];
xy = [x y]; % I concat x and y for convenience
while 1
% Find the first available zero-crossing index of V
idx = find(abs(diff(sign(V)))==2, 1);
if isempty(idx)
break
end
% Interpolate xy at that zero
newXY = interp1(V(idx:idx+1),xy(idx:idx+1,:),0);
% Concat the results into xy and V
xy = [xy(1:idx,:); newXY; xy(idx+1:end,:)];
V = [V(1:idx); 0; V(idx+1:end)];
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!