-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmat2arff.m
46 lines (38 loc) · 1.06 KB
/
mat2arff.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
function mat2arff(M, filename, gt)
% mat2arff(M, filename, gt)
%
% Save the matrix M as a Weka ARFF file. Make up names for the
% columns. If gt argument is provided, use that as the class,
% otherwise give everything the same class.
% Copyright (C) 2005 Michael Mandel, mim at ee columbia edu;
% distributable under GPL
file = fopen(filename, 'w');
% Print comments at top of file
fprintf(file, ['% ' filename '\n']);
fprintf(file, '% This file was automatically generated by mat2arff\n');
% Print header info
fprintf(file, ['@RELATION ' filename '\n\n']);
colnums = [1:size(M,2)];
fprintf(file, '@ATTRIBUTE f%d NUMERIC\n', colnums);
% Print list of classes
fprintf(file, '@ATTRIBUTE class {');
if(nargin < 3)
fprintf(file, 'n,y,');
else
fprintf(file, 'c%d,',unique(gt));
end
fprintf(file, '\b}\n\n');
% Print data section
fprintf(file, '@DATA\n');
if(nargin < 3)
for i=1:size(M,1)
fprintf(file, '%f,', M(i,:));
fprintf(file, 'n\n');
end
else
for i=1:size(M,1)
fprintf(file, '%f,', M(i,:));
fprintf(file, 'c%d\n', gt(i));
end
end
fclose(file);