-
Notifications
You must be signed in to change notification settings - Fork 9
/
WriteData.m
35 lines (32 loc) · 1006 Bytes
/
WriteData.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
% Jun-Yan Zhu (junyanz at eecs dot berkeley dot edu)
% University of California, Berkeley
% Write Matlab data to a text file
function [] = WriteData(data, dataFile)
fid = fopen(dataFile, 'wt');
if fid == -1
fprintf('cannot write file (%s)\n', dataFile);
else
fprintf(fid, '%d %d\n', data.numInsts, data.numFtrs);
countInst = 0;
numFtrs = data.numFtrs;
for n = 1 : data.numBags
bag = data.bags{n};
label = bag.label;
bagId = bag.id;
% id = bag.bag
for k = 1 : bag.numInst
inst = bag.insts{k};
fprintf(fid, '%d:%d:%d ', countInst, bagId, label);
countInst = countInst + 1;
tmp = zeros(numFtrs*2,1);
tmp(1:2:end) = 1 : numFtrs;
tmp(2:2:end) = inst.ftr;
% for l = 1 : numFtrs
fprintf(fid, '%d:%f ', tmp);
% end
fprintf(fid, '\n');
end
end
fclose(fid);
end
end