• Linux中Matlab保存多个数据到同一个文件当中


    % 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 calhousing
      path= '/root/orca-master0/orca-master/';
      name='CaliforniaScaling';
      NumTrainforScaling =  [100:100:900,1000:1000:10000] ;
     for i = 1:length(NumTrainforScaling)
    NumTrain = NumTrainforScaling(i);
    
    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=[targets-1,traindata];
    n0 = size(X1,2);
    X1 = sortrows(X1,1);
    
    X2=[TestTargets-1,TestData];
    
    % traindata = X1(:,1:end-1);
    % targets = X1(:,end);
    
    % X1=[traindata,targets];
    
    % fname1 = strcat('C:UsershdDesktopmachinemytask_train.',num2str(k-1));
    % fname2 = strcat('C:UsershdDesktopmachinemytask_test.',num2str(k-1));
    
    % fname1 = strcat('C:UsershdDesktophousingmytask_train.',num2str(k-1));
    % fname2 = strcat('C:UsershdDesktophousingmytask_test.',num2str(k-1));
    
    % fname1 = strcat('C:UsershdDesktopabalonemytask_train.',num2str(k-1));
    % fname2 = strcat('C:UsershdDesktopabalonemytask_test.',num2str(k-1));
    
    % fname1 = strcat('C:UsershdDesktopank32nhmytask_train.',num2str(k-1));
    % fname2 = strcat('C:UsershdDesktopank32nhmytask_test.',num2str(k-1));
    
    % fname1 = strcat('C:UsershdDesktopcpuactmytask_train.',num2str(k-1));
    % fname2 = strcat('C:UsershdDesktopcpuactmytask_test.',num2str(k-1));
    
    %  fname1 = strcat('C:UsershdDesktopcalhousingmytask_train.',num2str(k-1));
    %  fname2 = strcat('C:UsershdDesktopcalhousingmytask_test.',num2str(k-1));
     
    %  fname1 = strcat('C:UsershdDesktopcensusmytask_train.',num2str(k-1));
    %  fname2 = strcat('C:UsershdDesktopcensusmytask_test.',num2str(k-1));
    path =  '/root/nnrank1.2/data/';
    fname1 = strcat(path,name,'/mytask_train.',num2str(k-1));
    fname2 = strcat(path,name,'/mytask_test.',num2str(k-1));
    fname3 = strcat(path,name,'/mytask_targets.',num2str(k-1));
    
    %  fname1 = strcat('C:UsershdDesktopscalecalhousingmytask_train.',num2str(k-1));
    % libsvmwrite(fname1, targets, sparse(traindata));
    
    
    % save(fname1,'X1','-ascii')
    % %save(fname2,'X2','-ascii')
    %  save(fname2,'TestData','-ascii')
    %  save(fname3,'TestTargets','-ascii')
     
     
     TrainNNOP{1} = size(X1,2)-1;
     TrainNNOP{2} = [5, 0:4];
     TrainNNOP{3} = size(X1,1);
     TrainNNOP{4} = X1;
     
     TestNNOP{1} = size(X2,2)-1;
     TestNNOP{2} = [5, 0:4];
     TestNNOP{3} = size(X2,1);
     TestNNOP{4} = X2;
     
     for j = 1:4
         dlmwrite(fname1,TrainNNOP{j},'delimiter', ' ','-append'); 
    %      dlmwrite(fname2,TestNNOP{j},'delimiter', '	');
     end
    
    % libsvmwrite(fname1, targets, sparse(traindata));
    % libsvmwrite(fname2, TestTargets, sparse(TestData));
    
    % end
      end
    
  • 相关阅读:
    如何在windows 11中安装WSLG(WSL2)
    JavaScript中一些有关数组的API
    49 个在工作中常用且容易遗忘的 CSS 样式清单整理(转)
    MAC的一些命令
    高级前端进阶(一)
    kindEditor参数详解
    kindEditor用法总结
    kindEditor用法
    Object浅拷贝、深拷贝
    api连接Kafka报错:java.net.UnknownHostException: VM-0-12-centos: nodename nor servname provided, or not known
  • 原文地址:https://www.cnblogs.com/huadongw/p/5171554.html
Copyright © 2020-2023  润新知