-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_osimm.m
More file actions
57 lines (50 loc) · 1.42 KB
/
make_osimm.m
File metadata and controls
57 lines (50 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function make_osimm(filename,dof_names,angles,time)
% Creates motion file for OpenSim
%
% Inputs:
% filename: the name of the motion file, without the extension
% angles: an num_dofs x n or n x num_dofs matrix of angles in radians,
% n the number of frames
% time (optional): a 1xn or nx1 vector of time values. If this is not
% provided, the timestep is assumed to be 0.01s.
%
% Corrected: angles now in radians instead of degrees
% Dimitra Blana, February 2012
[nrows,ncolumns]=size(angles);
if ncolumns~=length(dof_names)
angles=angles';
nrows = ncolumns;
end
if nargin <4
time = 0.01:0.01:0.01*nrows;
end
if size(time,2)~=1, time = time'; end
if size(time,1)~=nrows
errordlg('The time vector does not have the same length as the angle data.','Dimension error');
return;
end
data = [time angles];
% create motion file
% the header of the motion file is:
%
% <motion name>
% nRows=x
% nColumns=y
% endheader
% time dofnames
%
dofnames = 'time';
dofstr = '%f';
for idof = 1:length(dof_names)
dofnames= [dofnames ' ' dof_names{idof}];
dofstr = [dofstr ' %f'];
end
dofstr = [dofstr '\n'];
fid = fopen([filename '.sto'],'wt');
fprintf(fid,'%s\n',filename);
fprintf(fid,'%s%i\n','nRows=',nrows);
fprintf(fid,'%s\n',['nColumns=' num2str(length(dof_names)+1)]);
fprintf(fid,'%s\n','endheader');
fprintf(fid,'%s\n',dofnames);
fprintf(fid,dofstr,data');
fclose(fid);