Saving data from a loop in an array
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
KSSV
am 18 Jun. 2019
Bearbeitet: KSSV
am 18 Jun. 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu File Operations 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!