Saving data from a loop in an array

1 回表示 (過去 30 日間)
Anton
Anton 2019 年 6 月 18 日
コメント済み: Anton 2019 年 6 月 18 日
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

採用された回答

KSSV
KSSV 2019 年 6 月 18 日
編集済み: KSSV 2019 年 6 月 18 日
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 件のコメント
Anton
Anton 2019 年 6 月 18 日
Great, thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by