필터 지우기
필터 지우기

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by