-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_ascii_sym.m
83 lines (52 loc) · 1.38 KB
/
export_ascii_sym.m
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function export_ascii_sym(MAT_SYM,FILENAME,MAT_NAME)
% Usage example
%
% export_ascii_sym(symbolic_matrix,'file','matrix_name')
%
% where
% symbolic_matrix is the name of a symbolic matrix
% present in the workspace
%
% 'file' is the filename where the ascii information
% will be stored
%
% 'matrix_name' is the resulting matrix of the function
% The last two fields must be either 'char' type
% variables or strings within characters "'"
%
% The function assigns "file.m" as the function file.
%
% Thank you very much for your patience
[m,n]=size(MAT_SYM);
character=char(MAT_SYM);
sym_variables=symvar(character);
clear character;
full_filename=[FILENAME,sprintf('.m')];
fid = fopen(full_filename,'w');
fprintf(fid,'function [%s]= %s(',MAT_NAME,FILENAME);
for i=1:1:size(sym_variables,1),
if i==size(sym_variables,1),
fprintf(fid,'%s)',char(sym_variables(i)));
else
fprintf(fid,'%s, ',char(sym_variables(i)));
end
end
fprintf(fid,'\n%% Depending variables :\n');
for i=1:1:size(sym_variables,1),
fprintf(fid,'%% \t\t\t\t\t\t %s \n',char(sym_variables(i)));
end
fprintf(fid,'\n');
fprintf(fid,'%s = [\n',MAT_NAME);
for i=1:1:m,
for j=1:1:n,
aux=char(MAT_SYM(i,j));
if j==n,
fprintf(fid,'%s',aux);
else
fprintf(fid,'%s, ',aux);
end
end
fprintf(fid,'; \n');
end
fprintf(fid,'];');
fclose(fid);