write_svm_data.m
来自「最新的模式识别分类工具箱,希望对朋友们有用!」· M 代码 · 共 38 行
M
38 行
function make_svmdata(features, labels, filename)
%Make a BSVM-format data file from a features matrix
%Inputs:
% features - A matrix of features of size #features x #points
% labels - A vector of labels (targets) corresponding to the
% number of points in the features matrix
% filename - The name of the file to be created
if (size(features,2) ~= length(labels)),
error('Features and labels do not match in length!');
end
fid = fopen(filename, 'w');
if (fid == -1),
error('Could not open the file');
end
[c,r] = size(features);
for i = 1:r,
%Write the label
if (labels(i) < 1)
fprintf(fid, '-1 ');
else
fprintf(fid, '+1 ');
end
for j=1:c,
fprintf(fid, '%i:%f ', j, features(j,i));
end
fprintf(fid, char(13));
fprintf(fid, char(10));
end
fclose(fid);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?