MATLAB: Error Explanation Error: File: C.m Line: 169 Column: 5 This statement is not inside any function. (It follows the END that terminates the definition of the function “readeph”.)

errorMATLAB

question complete

Best Answer

I edited the function for you ...starting with fixing the indention to be consistent by block...which shows when you get back to original level you've closed the last block for the function() definition prematurely.
I removed all th top comments and other preparatory work at beginning of the file to let the issues be more easily visible in a very long function file...you can reinsert that or move the edits over (or ignore them as see fit).
function [gpseph,galeph,bdseph,gloeph] = readeph(file_name) % REMOVE trailing ":"
% [gpseph,galeph,bdseph,gloeph] = readeph(file_name);
....
% Now that the file pointer is set to the first satellite ephemeris,
% read it and store the data for conversion to the standard Toolbox
% ephemeris format. Set the end of file flag (eof_flag) to zero.
eof_flag = 0; % end of file not found
eph_count = 1;
% Read in all of the data as characters. Replace the Ds with Es. Write
% the modified data out to the temp file.
[data, num_read] = fscanf(fid,'%c');
c = fprintf(fid_temp,'%c',data);
fid_temp = fopen('temp.dat','r');
nLine = zeros(1,4);
noLinesGPS = 8;
noLinesGLONASS = 4;
noLinesGALILEO = 8;
noLinesBEIDOU = 8;
idxGPS = 1;
idxGLONASS = 1;
idxGALILEO = 1;
idxBEIDOU = 1;
%while true
while ~feof(fid) % USE FEOF() instead of fake condition
txtLine = fgetl(fid_temp);
if (txtLine == -1)|isempty(txtLine), break; end % Shorten the test logic expression
% USE SWITCH CONSTRUCT INSTEAD OF COMPLICATED IF...ELSEIF...
% MORE THAN LIKELY THE MULTIPLE VARIABLES HERE CAN BE HANDLED MORE EFFICIENTLY AND GENERICALLY
% BUT I MADE NO ATTEMPT TO TRY TO DECIPHER WHAT'S BEING DONE IN ORDER TO DO SO.
switch txtLine(1)
case 'G'
dataGPS{idxGPS} = txtLine;
for nLine = 1:noLinesGPS
txtLine = fgetl(fid_temp);
dataGPS{idxGPS} = sprintf('%s %s', dataGPS{idxGPS}, txtLine);
end
idxGPS = idxGPS + 1;
case 'R'
dataGLONASS{idxGLONASS} = txtLine;
for nLine = 1:noLinesGLONASS
txtLine = fgetl(fid_temp);
dataGLONASS{idxGLONASS} = sprintf('%s %s', dataGLONASS{idxGLONASS}, txtLine);
end
idxGLONASS = idxGLONASS + 1;
case 'E'
dataGALILEO{idxGALILEO} = txtLine;
for nLine = 1:noLinesGALILEO
txtLine = fgetl(fid_temp);
dataGALILEO{idxGALILEO} = sprintf('%s %s', dataGALILEO{idxGALILEO}, txtLine);
end
idxGALILEO = idxGALILEO + 1;
case 'C'
dataBEIDOU{idxBEIDOU} = txtLine;
for nLine = 1:noLinesBEIDOU
txtLine = fgetl(fid_temp);
dataBEIDOU{idxBEIDOU} = sprintf('%s %s', dataBEIDOU{idxBEIDOU}, txtLine);
end
idxBEIDOU = idxBEIDOU + 1;
end % switch txtLine(1)
end % while true
end % function readeph here
% EVERYTHING HEREAFTER IS OUTSIDE THE FUNCTION AND JUST RANDOM CODE THAT CAN"T BE THERE.
% EITHER YOU INSERTED AN EXTRA END OR YOU STARTED ADDING AT THE END OF THE FILE
% BUT IT LOOKS LIKE _PROBABLY_ THE FORMER -- PERHAPS WHILE ADDING THE IF...ELSEIF... BLOCK
% (WHICH, BTW, I TURNED INTO THE MUCH MORE LEGIBLE SWITCH CONSTRUCT
...