MATLAB筛选数据

MATLAB筛选数据

0.前言

任务要求如下;
把36万行的数据集筛选出来,只剩下1800多行

1.程序代码

%% 

clear;
clc;
filename_Old = 'WLTC.XLS';


[~,Sheet,~]=xlsfinfo(filename_Old); % 求出文件有多少个sheet
cell_array = [] ;

process_show=waitbar(0,'检查进度'); %显示初始界面
for i= 1:length(Sheet)
    [~,~,total_number] = xlsread(filename_Old,Sheet{i}); % 因为一个sheet最多是65501行

     Percentage = i/length(Sheet);
     waitbar(Percentage,process_show,['已完成'  (num2str(round(100*Percentage)))  '%']); %进度条,进度增加情况 后面有判断是否关闭
    flag_5_test = 1; % 用来标志 每10个就取一次值
    for VehicleSpeed_i = 1:length(total_number)   % 因为一个sheet最多是65501行
        
        if isnan(total_number{VehicleSpeed_i,4}) | strcmp(char(total_number{VehicleSpeed_i,4}) , 'ESP_VehicleSpeed[km/h]' )  % 为空则跳过
            continue;
        
        else % 表示有数据 则记录当前的行数
            flag_5_test  =flag_5_test + 1;
            if mod(flag_5_test,10) == 0 %如果是能被10整除
                try %错误判断

                  %% 取出 Time 值
                   Current_Time = round(total_number{VehicleSpeed_i,1});

                 %% 取出 EMS_EngineSpeed 值
                  EMS_EngineSpeed = round(total_number{VehicleSpeed_i-1,2});

                %% 取出 EMS_IndicatedRealEngTorq 值
                 EMS_IndicatedRealEngTorq = round(total_number{VehicleSpeed_i+1,3});

                %% 取出 ESP_VehicleSpeed 值
                 ESP_VehicleSpeed =round (total_number{VehicleSpeed_i,4});

                catch
                 EMS_EngineSpeed = round(total_number{VehicleSpeed_i-1,2});

                %% 取出 EMS_IndicatedRealEngTorq 值
                EMS_IndicatedRealEngTorq = round(total_number{VehicleSpeed_i-2,4});

                end
            
            %% 把读取的4个数据依次写入新表中
      
            Data_need = [ Current_Time ,EMS_EngineSpeed ,EMS_IndicatedRealEngTorq ,ESP_VehicleSpeed ];     

            cell_array = [cell_array;Data_need]; % 按照列来存储
%             cell_array = [cell_array,Data_need]; % 按照行来存储

            end
        end
    end
   
end
close(process_show);% 循环结束,关闭进度条
disp('正在保存数据...')
save cell_array
disp('保存成功')

cell_array=load('cell_array.mat'); %a是一个的mat数据
X_time = cell_array.cell_array(:,1);

y1_EMS_EngineSpeed = cell_array.cell_array(:,2);

y2_IndicatedRealEngTorq = cell_array.cell_array(:,3);
y3_VehicleSpeed = cell_array.cell_array(:,4);

plot(X_time,y1_EMS_EngineSpeed,X_time,y2_IndicatedRealEngTorq,X_time,y3_VehicleSpeed)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值