datetime - MATLAB: Read Excel file and find zeroes for a specific time range -


i need read excel file table this:

name   | time   | score ------ | ------ | ------ bill   | 11:15  | 2.4 bill   | 13:00  | 0 bill   | 20:00  | 0 steve  | 6:00   | 4.7 steve  | 13:45  | 0 steve  | 17:45  | 3 jack   | 9:00   | 0 jack   | 13:30  | 7.2 jack   | 19:30  | 0 

and return names of people score 0 between 13:00 , 14:00. correct answer in example be:

name   |  ------ |  bill   | steve  | 

this current code:

x = xlsread(filename); [row,col] = size(x); = 1:row     j = 1:col         if x{i,2} == '13:00' && x{i,3} == 0             y = x{i,1};         end     end end 

i'm not sure how solve multiple 'hh:mm' values on requested time range. appreciated.

first, need use additional outputs xlsread text , numeric data:

[score, textdata] = xlsread('temp.xlsx'); 

next, you'll want convert second column of text (your time data) format easier comparisons on, serial date number:

timedata = datenum(textdata(2:end, 2)); 

now can create logical indices showing rows have score of 0 , time within given range:

index = (score == 0) & (timedata >= datenum('13:00')) & (timedata <= datenum('14:00')); 

and can use index select corresponding names (using unique remove repeated names):

namedata = textdata(2:end, 1); unique(namedata(index))  ans =    2×1 cell array      'bill'     'steve' 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -