function Lec02_01_file(fn) % LEC02_01_FILE: Either requests a file name or uses one % passed to it. % Matlab test of file operations % This function reads GPS position files generated by the MIT processing % software ensum (file names start with mb_ and end in 1/2 or 3) % This comment is not listed with help % fid = 0; if nargin == 0 filename = input('Open file: ','s'); else filename = fn end [fid, message] = fopen(filename,'r'); if fid == -1 disp(message) ok = 0; return end % Now we will try to read the file. These % files have three header lines and then data % % Read the header lines H1 = fgetl(fid); H2 = fgetl(fid); disp(H2) H3 = fgetl(fid); % The rest of the file is numeric with three values per lines and we % can read all at once [Data,tot] = fscanf(fid,' %f %f %f'); % Close the data file at this point fclose(fid); % Now reshape the Data into 3:tot/3 array num = tot/3; Data = reshape(Data,3,num); % Now make a simple plot of the data hold off figure(1) errorbar(Data(1,:),Data(2,:),Data(3,:),'ro'); hold on hp = plot(Data(1,:),Data(2,:),'bo'); % Save the graphics handle set(hp,'MarkerFaceColor',[1 1 0]); figure(1) %display('Press any key to continue') %pause disp('Removing large sigma points') response = questdlg('Paused: Remove large sigmas next'); if ~strcmp(response,'Yes') fprintf('Response was %s, removing large sigma anyway\n',response); end % An alternative method (need testbut.m and testbut.fig) %testbut; % Now use the find command to remove points with large error bars GoodSig = find(Data(3,:)<0.020); Data = [Data(1,GoodSig); Data(2,GoodSig); Data(3,GoodSig)]; figure(2) hold off errorbar(Data(1,:),Data(2,:),Data(3,:),'ro'); hold on hp = plot(Data(1,:),Data(2,:),'bo'); % Save the graphics handle set(hp,'MarkerFaceColor',[1 1 1]); %disp('Press eny key to continue') %pause questdlg('Paused: Remove mean next'); % We might want to demean and change the units to mm as well MeanData = mean(Data(2,:)); fprintf(1,'Removing mean of %8.4f m from data\n',MeanData) Data(2,:) = (Data(2,:) - MeanData)*1000; Data(3,:) = Data(3,:)*1000; figure(3) hold off errorbar(Data(1,:),Data(2,:),Data(3,:),'ro'); hold on hp = plot(Data(1,:),Data(2,:),'bo'); % Save the graphics handle set(hp,'MarkerFaceColor',[1 1 0]); ylabel('Position (mm)'); xlabel('Date'); tlabel = ['Data file ' strrep(filename,'_','\_') ' \Delta from mean' ] %title(strrep(strcat('Data file ',filename),'_','\_')) title(tlabel) figure(3);