function [cutdatehours, cutdischarges]=findrange(filename, startdate, stopdate, mode) %invoke me with % [times qs]=findrange('mkel.txt','4/14/03 22:00:00', '4/16/2003 12:00:00',0); % note that the mode of 0 shows the date as mm/dd/yyyy hh:mm:ss % mode of 6 is mm/dd % mode of 13 is hh:mm:ss [date,hour,gage,discharge]=textread(filename,'%s %s %f %f'); datehour=strcat(date, 'space',hour); datehourclean=strrep(datehour,'space',' '); %datehourconverted=datenum(char(datehourclean))./365.24 datehourconverted=datenum(char(datehourclean)); start=datenum(char(startdate)); stop=datenum(char(stopdate)); startlocationmatrix=datehourconverted>=start; stoplocationmatrix=datehourconverted<=stop; locationmatrix=startlocationmatrix.*stoplocationmatrix; locs=find(locationmatrix); cutdatehours=datehourconverted(locs); cutdischarges=discharge(locs); figure(1) clf hold on plot(cutdatehours, cutdischarges, 'b-') xlabel('date') ylabel('discharge (cfs)') axis([start stop 0 max(cutdischarges)]) datetick('x',mode)