Saving data from a loop in an array

1 visualización (últimos 30 días)
Anton
Anton el 18 de Jun. de 2019
Comentada: Anton el 18 de Jun. de 2019
So I have this code that calculates the inproduct of two vectors. I need the answers (being C), to be saved in an array. How do I do this?
clc
clear all
close all
dir = 'C:\Users\Anton\Documents\MATLAB\';
file = 'Rennen_meting_3.mat';
Visualizedata = true;
load([dir file])
for j = 1:10:length(Data.Time)
x1 = Data.VIZmarker(1).Pos(j,1);
y1 = Data.VIZmarker(1).Pos(j,2);
z1 = Data.VIZmarker(1).Pos(j,3);
x2 = Data.VIZmarker(2).Pos(j,1);
y2 = Data.VIZmarker(2).Pos(j,2);
z2 = Data.VIZmarker(2).Pos(j,3);
x3 = Data.VIZmarker(3).Pos(j,1);
y3 = Data.VIZmarker(3).Pos(j,2);
z3 = Data.VIZmarker(3).Pos(j,3);
x4 = Data.VIZmarker(4).Pos(j,1);
y4 = Data.VIZmarker(4).Pos(j,2);
z4 = Data.VIZmarker(4).Pos(j,3);
x5 = Data.VIZmarker(5).Pos(j,1);
y5 = Data.VIZmarker(5).Pos(j,2);
z5 = Data.VIZmarker(5).Pos(j,3);
M1 = [x1 y1 z1];
M2 = [x2 y2 z2];
M3 = [x3 y3 z3];
M4 = [x4 y4 z4];
M5 = [x5 y5 z5];
A = (M1-M4); %vector van de heup naar de knie
B = (M1-M3); %vector van de enkel naar de knie
C = dot(A,B)
end

Respuesta aceptada

KSSV
KSSV el 18 de Jun. de 2019
Editada: KSSV el 18 de Jun. de 2019
clc
clear all
close all
dir = 'C:\Users\Anton\Documents\MATLAB\';
file = 'Rennen_meting_3.mat';
Visualizedata = true;
load([dir file])
C = zeros([],1) ; % Initialize to store C
count = 0 ;
for j = 1:10:length(Data.Time)
x1 = Data.VIZmarker(1).Pos(j,1);
y1 = Data.VIZmarker(1).Pos(j,2);
z1 = Data.VIZmarker(1).Pos(j,3);
x2 = Data.VIZmarker(2).Pos(j,1);
y2 = Data.VIZmarker(2).Pos(j,2);
z2 = Data.VIZmarker(2).Pos(j,3);
x3 = Data.VIZmarker(3).Pos(j,1);
y3 = Data.VIZmarker(3).Pos(j,2);
z3 = Data.VIZmarker(3).Pos(j,3);
x4 = Data.VIZmarker(4).Pos(j,1);
y4 = Data.VIZmarker(4).Pos(j,2);
z4 = Data.VIZmarker(4).Pos(j,3);
x5 = Data.VIZmarker(5).Pos(j,1);
y5 = Data.VIZmarker(5).Pos(j,2);
z5 = Data.VIZmarker(5).Pos(j,3);
M1 = [x1 y1 z1];
M2 = [x2 y2 z2];
M3 = [x3 y3 z3];
M4 = [x4 y4 z4];
M5 = [x5 y5 z5];
A = (M1-M4); %vector van de heup naar de knie
B = (M1-M3); %vector van de enkel naar de knie
count = count+1 ;
C(count) = dot(A,B) ;
end
C

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by