Creating a vector from two points using 3 coordinates

1 Ansicht (letzte 30 Tage)
Anton
Anton am 12 Jun. 2019
Kommentiert: Guillaume am 12 Jun. 2019
I'm trying to create two vectors from two points created from a set of data. The data set contains 3106 values. I need something like a loop for this to work, so i can plot the length of these two vectors over time.
fyi: The vectors are the force projected on the ground while running.
In the end I need an array of the length of both vectors.
This is what i got so far:
j = 1:10:length(Data.Time)
x0_l=Data.XPC_FP1COP(j,1);
y0_l=zeros(length(Data.Time),1);
z0_l=Data.XPC_FP1COP(j,2);
x0_r=Data.XPC_FP2COP(j,1);
y0_r=zeros(length(Data.Time),1);
z0_r=Data.XPC_FP2COP(j,2);
x_l=Data.XPC_FP1GRF(j,1);
y_l=Data.XPC_FP1GRF(j,1);
z_l=Data.XPC_FP1GRF(j,1);
x_r=Data.XPC_FP2GRF(j,1);
y_r=Data.XPC_FP2GRF(j,1);
z_r=Data.XPC_FP2GRF(j,1);
Ground_l = [x0_l,y0_l,z0_l];
Ground_r = [x0_r,y0_r,z0_r];
Top_l = [x_l,y_l,z_l];
Top_r = [x_l,y_l,z_l];
F_l = Ground_l - Top_l
F_r = Ground_r - Top_r
  3 Kommentare
Anton
Anton am 12 Jun. 2019
Bearbeitet: Anton am 12 Jun. 2019
Okay, I'll try to rephrase.
I have got data of a starting point and an ending point of a vector. Of both these points I have a matrix of 3160x3, being measurements for x, y and z. each row being a certain time that the point was measured. What I want the code to do is to eventually plot the length of this line between the two points against time. How do I get this to work?
Is this clearer?
I rewrote the code that I have below. I also changed the y0, so that it corrosponds with the lengths of x0 and z0.
j = 1:10:length(Data.Time)
x0 = Data.XPC_FP1COP(j,1);
y0 = zeros(length(j),1);
z0 = Data.XPC_FP1COP(j,2);
x = Data.XPC_FP1GRF(j,1);
y = Data.XPC_FP1GRF(j,2);
z = Data.XPC_FP1GRF(j,3);
Start = [x0,y0,z0];
End = [x,y,z];
F = End - Start
Guillaume
Guillaume am 12 Jun. 2019
Bearbeitet: Guillaume am 12 Jun. 2019
My understanding is that you have two points moving through a 3D space. And it sounds like the distance between these two points vary in time.
No idea what the length of the line refers to? What line? Do you mean that you want to plot the distance between the two points with time?
And by distance, do you mean euclidean distance (i.e )?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Matt J
Matt J am 12 Jun. 2019
Bearbeitet: Matt J am 12 Jun. 2019
I think this would complete your code.
Times=1:10:length(Data.Time);
J=numel(Times);
F=nan(J,3);
for j = 1:J
x0 = Data.XPC_FP1COP(j,1);
y0 = zeros(length(j),1);
z0 = Data.XPC_FP1COP(j,2);
x = Data.XPC_FP1GRF(j,1);
y = Data.XPC_FP1GRF(j,2);
z = Data.XPC_FP1GRF(j,3);
Start = [x0,y0,z0];
End = [x,y,z];
F(j,:) = End - Start;
end
plot(vecnorm(F,2,2))
  1 Kommentar
Guillaume
Guillaume am 12 Jun. 2019
Is there any point to the loops? I would assume that:
rows = 1:10:numel(Data.Time); %and if Data is a table use height(Data)
F = Data.XPC_FP1GRF(rows, 1:3) - [Data.XPC_FP1COP(rows, 1), zeros(numel(rows), 1), Data.XPC_FP1COP(rows, 3)];
plot(vecnorm(F, 2, 2));
would achieve the same result.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by