MATLAB筛选数据
生活随笔
收集整理的這篇文章主要介紹了
MATLAB筛选数据
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
MATLAB篩選數(shù)據(jù)
文章目錄
- MATLAB篩選數(shù)據(jù)
- 0.前言
- 1.程序代碼
0.前言
任務(wù)要求如下;
把36萬(wàn)行的數(shù)據(jù)集篩選出來(lái),只剩下1800多行
1.程序代碼
%% clear; clc; filename_Old = 'WLTC.XLS';[~,Sheet,~]=xlsfinfo(filename_Old); % 求出文件有多少個(gè)sheet cell_array = [] ;process_show=waitbar(0,'檢查進(jìn)度'); %顯示初始界面 for i= 1:length(Sheet)[~,~,total_number] = xlsread(filename_Old,Sheet{i}); % 因?yàn)橐粋€(gè)sheet最多是65501行Percentage = i/length(Sheet);waitbar(Percentage,process_show,['已完成' (num2str(round(100*Percentage))) '%']); %進(jìn)度條,進(jìn)度增加情況 后面有判斷是否關(guān)閉flag_5_test = 1; % 用來(lái)標(biāo)志 每10個(gè)就取一次值for VehicleSpeed_i = 1:length(total_number) % 因?yàn)橐粋€(gè)sheet最多是65501行if isnan(total_number{VehicleSpeed_i,4}) | strcmp(char(total_number{VehicleSpeed_i,4}) , 'ESP_VehicleSpeed[km/h]' ) % 為空則跳過(guò)continue;else % 表示有數(shù)據(jù) 則記錄當(dāng)前的行數(shù)flag_5_test =flag_5_test + 1;if mod(flag_5_test,10) == 0 %如果是能被10整除try %錯(cuò)誤判斷%% 取出 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});catchEMS_EngineSpeed = round(total_number{VehicleSpeed_i-1,2});%% 取出 EMS_IndicatedRealEngTorq 值EMS_IndicatedRealEngTorq = round(total_number{VehicleSpeed_i-2,4});end%% 把讀取的4個(gè)數(shù)據(jù)依次寫(xiě)入新表中Data_need = [ Current_Time ,EMS_EngineSpeed ,EMS_IndicatedRealEngTorq ,ESP_VehicleSpeed ]; cell_array = [cell_array;Data_need]; % 按照列來(lái)存儲(chǔ) % cell_array = [cell_array,Data_need]; % 按照行來(lái)存儲(chǔ)endendendend close(process_show);% 循環(huán)結(jié)束,關(guān)閉進(jìn)度條 disp('正在保存數(shù)據(jù)...') save cell_array disp('保存成功')cell_array=load('cell_array.mat'); %a是一個(gè)的mat數(shù)據(jù) 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)總結(jié)
以上是生活随笔為你收集整理的MATLAB筛选数据的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Linux用wget和curl下载jdk
- 下一篇: Json-server简单实现mock数