Hi, I am trying to load dates and times from a file. For the first file everything works fine, but for the second file gives me matlab this error: ??? Error using ==> horzcat CAT arguments dimensions are not consistent.
The weird thing is, these files contains almost the same values. They are different in only one number. Can somebody please tell me, how to modify Matlab file to be working with both files? Thanks for answers.
content of loadDatesAndTimes.m
loadedFile=uigetfile('*.txt');fid = fopen(loadedFile);% skip first line in the file
fscanf(fid, '%c',32);datetest = 0;i = 0;while ~feof(fid) i=i+1; year = fscanf(fid,'%i',4); fscanf(fid,'%c',1); month = fscanf(fid,'%i',2); fscanf(fid,'%c',1); day = fscanf(fid,'%i',1); fscanf(fid,'%c',1); hour = fscanf(fid,'%i',2); fscanf(fid,'%c',1); minute = fscanf(fid,'%i',1); datetest(1,i) = datenum([num2str(year),' ',num2str(month),' ',num2str(day),' ',num2str(hour),' ',num2str(minute)], 'yyyy mm dd HH MM'); fscanf(fid,'%c',1); if ( strcmp(fscanf(fid,'%c',4),'none') ) % compare strings
datetest(2,i) = 0; % device is OK
else status = fseek(fid,-4,'cof'); % return 4 characters back and start reading
year = fscanf(fid,'%i',4); fscanf(fid,'%c',1); month = fscanf(fid,'%i',2); fscanf(fid,'%c',1); day = fscanf(fid,'%i',1); fscanf(fid,'%c',1); hour = fscanf(fid,'%i',2); fscanf(fid,'%c',1); minute = fscanf(fid,'%i',1); datetest(2,i) = datenum([num2str(year),' ',num2str(month),' ',num2str(day),' ',num2str(hour),' ',num2str(minute)], 'yyyy mm dd HH MM'); end % end if
end % end while
fclose(fid);format('long')disp(datetest*24);
content of first text file
start time time of failure2011.01.01 00:00 2011.01.01 06:002011.01.01 06:00 none2011.01.01 00:00 none2011.01.01 00:00 2011.01.01 03:002011.01.01 00:00 2011.01.01 07:00
content of second text file
start time time of failure2011.01.01 00:00 2011.01.01 06:002011.01.01 06:00 none2011.01.01 00:00 none2011.01.01 00:00 2011.01.01 03:002011.01.01 00:00 2011.01.01 08:00
Best Answer