Saving data from a loop in an array

1 vue (au cours des 30 derniers jours)
Anton
Anton le 18 Juin 2019
Commenté : Anton le 18 Juin 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

Réponse acceptée

KSSV
KSSV le 18 Juin 2019
Modifié(e) : KSSV le 18 Juin 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
  1 commentaire
Anton
Anton le 18 Juin 2019
Great, thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by