Tapk1ng
1TaPK1ng
采纳率0%
2019-06-10 11:14

怎么用matlab实现excel的筛选排序?

20

现在需要将excel的数据提取到matlab,然后以温度大小对数据进行升序排序,接着以时间早晚对拍好的数据再次进行升序排序,excel数据样子如下,
图片说明

但是尝试sortrows函数后,

    [~,~,data] = xlsread(filename,Sheet{j});
    Data = data( 2 : end, 1 : end );
    Results = sortrows(Data , [ 2 1] , {'ascend' 'ascend'};

出现error如下,

图片说明

现在无法解决这个问题,后面还有数据分类应该怎么分类,我想让输出的数据分组为17摄氏度到18摄氏度为一组,以此类推,所以最后我的尝试为

filename = ('c:/users/44623/Documents/MATLAB/5min 室内.xlsx');

[~, Sheet, ~] = xlsfinfo(filename);
Y = char(Sheet);


for j = 1 : length(Sheet)

    [~,~,data] = xlsread(filename,Sheet{j});
    Data = data( 2 : end, 1 : end );
    Results = sortrows(Data , [ 2 1] , {'ascend' 'ascend'};

    sheet = '17 - 18';
    [aa,~] = find(Temp >= 17 & Temp < 18);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

    sheet = '18 - 19';
    [aa,~] = find(Temp >= 18 & Temp < 19);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

    sheet = '19 - 20';
    [aa,~] = find(Temp >= 19 & Temp < 20);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

    sheet = '20 - 21';
    [aa,~] = find(Temp >= 20 & Temp < 21);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

    sheet = '21 - 22';
    [aa,~] = find(Temp >= 21 & Temp < 22);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

    sheet = '22 - 23';
    [aa,~] = find(Temp >= 22 & Temp < 23);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

    sheet = '23 - 24';
    [aa,~] = find(Temp >= 23 & Temp < 24);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

    sheet = '24 - 25';
    [aa,~] = find(Temp >= 24 & Temp < 25);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

    sheet = '25 - 26';
    [aa,~] = find(Temp >= 25 & Temp < 26);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

    sheet = '26 - 27';
    [aa,~] = find(Temp >= 26 & Temp < 27);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

    sheet = '27 - 28';
    [aa,~] = find(Temp >= 27 & Temp < 28);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

    sheet = '28 - 29';
    [aa,~] = find(Temp >= 28 & Temp < 29);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

    sheet = '29 - 30';
    [aa,~] = find(Temp >= 29 & Temp < 30);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

    sheet = '30 - 31';
    [aa,~] = find(Temp >= 30 & Temp < 31);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

    sheet = '31 - 32';
    [aa,~] = find(Temp >= 31 & Temp < 32);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

    sheet = '32 - 33';
    [aa,~] = find(Temp >= 32 & Temp < 33);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

    sheet = '33 - 34';
    [aa,~] = find(Temp >= 33 & Temp < 34);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

    sheet = '34 - 35';
    [aa,~] = find(Temp >= 34 & Temp < 35);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

    sheet = '35 - 36';
    [aa,~] = find(Temp >= 35 & Temp < 36);
    xlswrite(['c:/users/44623/Documents/MATLAB/5min 室内/Temp',Y(j,:),'.xls'],[ data(1,:) ; Data(aa(1:end),:)],sheet);

end

不知道可不可以 有没有大佬能帮忙解答一下,很急的,谢谢谢谢!!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

相关推荐