码迷,mamicode.com
首页 > 其他好文 > 详细

MATLAB 生成数据保存至文件

时间:2015-10-26 01:55:55      阅读:386      评论:0      收藏:0      [点我收藏+]

标签:

 

% load pyrim
% NumTrain = 50;


% load machine
%NumTrain = 150;

% load housing
% NumTrain = 300;

% load abalone
% NumTrain = 1000;

% load bank32nh
% NumTrain = 3000;

% load cpuact
% NumTrain = 4000;

%  load calhousing
% NumTrain = 5000;

%  load census
% NumTrain = 6000;

load X4058
NumTrainforScaling =  [300,400] ;
name=‘X4058_300‘

i=1;
NumTrain = NumTrainforScaling(i);
for k = 1:20
n = size(X,1);
NumTest = n - NumTrain;
id = id0(k,:);
traindata = X(id(1:NumTrain),:);
targets = y(id(1:NumTrain));
TestData = X(id(NumTrain+1:n),:);
TestTargets = y(id(NumTrain+1:n));
X1=[traindata,targets];
fname1 = strcat(‘C:\Users\hd\Desktop\‘,name,‘\mytask_train.‘,num2str(k-1));
fname2 = strcat(‘C:\Users\hd\Desktop\‘,name,‘\mytask_test.‘,num2str(k-1));
% fname3 = strcat(‘C:\Users\hd\Desktop‘,name,‘\mytask_targets.‘,num2str(k-1));
libsvmwrite(fname1, targets, sparse(traindata));
libsvmwrite(fname2, TestTargets, sparse(TestData));
fname3 = strcat(‘E:\MATLAB\R2015a\bin\ADMM\CalOutData\mytask_targets.‘,num2str(k-1));
% save(fname1,‘X1‘,‘-ascii‘)
% save(fname2,‘TestData‘,‘-ascii‘)
save(fname3,‘TestTargets‘,‘-ascii‘)

end


%   load calhousing
%   NumTrainforScaling =  [300,400] ;
%  
%   i=1;
% NumTrain = NumTrainforScaling(i);
% for k=1:20
% k=i;
% % for k = 1:10
% n = size(X,1);
%  NumTest = n - NumTrain;
% % id = randperm(n);
% id = id0(k,:);
% traindata = X(id(1:NumTrain),:);
% targets = y(id(1:NumTrain));
% TestData = X(id(NumTrain+1:n),:);
% TestTargets = y(id(NumTrain+1:n));
% 
% % X1=[traindata,targets];
% 
% % fname1 = strcat(‘C:\Users\hd\Desktop\machine\mytask_train.‘,num2str(k-1));
% % fname2 = strcat(‘C:\Users\hd\Desktop\machine\mytask_test.‘,num2str(k-1));
% 
% % fname1 = strcat(‘C:\Users\hd\Desktop\housing\mytask_train.‘,num2str(k-1));
% % fname2 = strcat(‘C:\Users\hd\Desktop\housing\mytask_test.‘,num2str(k-1));
% 
% % fname1 = strcat(‘C:\Users\hd\Desktop\abalone\mytask_train.‘,num2str(k-1));
% % fname2 = strcat(‘C:\Users\hd\Desktop\abalone\mytask_test.‘,num2str(k-1));
% 
% % fname1 = strcat(‘C:\Users\hd\Desktop\bank32nh\mytask_train.‘,num2str(k-1));
% % fname2 = strcat(‘C:\Users\hd\Desktop\bank32nh\mytask_test.‘,num2str(k-1));
% 
% % fname1 = strcat(‘C:\Users\hd\Desktop\cpuact\mytask_train.‘,num2str(k-1));
% % fname2 = strcat(‘C:\Users\hd\Desktop\cpuact\mytask_test.‘,num2str(k-1));
% 
% %  fname1 = strcat(‘C:\Users\hd\Desktop\calhousing\mytask_train.‘,num2str(k-1));
% %  fname2 = strcat(‘C:\Users\hd\Desktop\calhousing\mytask_test.‘,num2str(k-1));
%  
% %  fname1 = strcat(‘C:\Users\hd\Desktop\census\mytask_train.‘,num2str(k-1));
% %  fname2 = strcat(‘C:\Users\hd\Desktop\census\mytask_test.‘,num2str(k-1));
% 
% fname1 = strcat(‘C:\Users\hd\Desktop\‘,name,‘\mytask_train.‘,num2str(k-1));
% fname2 = strcat(‘C:\Users\hd\Desktop\‘,name,‘\mytask_test.‘,num2str(k-1));
% libsvmwrite(fname1, targets, sparse(traindata));
% libsvmwrite(fname2, TestTargets, sparse(TestData));
% 
% 
% % save(fname1,‘X1‘,‘-ascii‘)
% % save(fname2,‘TestData‘,‘-ascii‘)
% % save(fname3,‘TestTargets‘,‘-ascii‘)
% 
% % libsvmwrite(fname1, targets, sparse(traindata));
% % libsvmwrite(fname2, TestTargets, sparse(TestData));

  

MATLAB 生成数据保存至文件

标签:

原文地址:http://www.cnblogs.com/huadongw/p/4910134.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!