MATLAB: A script doesn’t work by itself and just included in another script

errorrepmat

Hi there!
I have this script :
fid = uigetfile('*.sp3');
fid=fopen(fid);
fmt=[sat repmat('%f ',1,8)];
satSP3=[];
timpSP3=[];
while ~feof(fid)
l=fgetl(fid); % read a record
if l(1) =='*' % identificare timp pozitii sateliti
[p] = sscanf(l,'%c %d %d %d %d %d %d %d %d');
[gpsW,gpsS] = civil2GPStime (p(2), p(3), p(4), p(5), p(6), p(7));
end
%extragere pozitii pentru satelit X
if strfind(l,sat)
satSP3=[satSP3; cell2mat(textscan(l,fmt,'collectoutput',1))];
timpSP3 = [timpSP3; gpsS];
end
end
satSP3 = [satSP3(:,1:3) timpSP3];
fclose(fid);
When I press RUN I get this error :
Error in date_initiale_extragere_automata (line 4)
fmt=[sat repmat('%f ',1,8)];
And I have another script which includes the first one. When I run the second script I get no error. Could you please tell me where the problem is?
That's the script #2:
sat = 'PG04';
date_initiale_extragere_automata;
load_nav_param;
for i = 1:size(satSP3,1);
X = computemany(satSP3(i,4),toe,mo,a,deltan,e,omega,cuc,cus,crc,crs,io,idot,cic,cis,omegae,odot,omegao);
%nota bene in apelarea de mai sus am luat timpul din coloana a 4-a de
%pe linia curenta din satSP3
satEFEM (i,:) = X;
end
Thanks!

Best Answer

glbmtc - you haven't posted the error but I suspect the problem is that you haven't defined sat and so you are erroring on the line
fmt=[sat repmat('%f ',1,8)];
with (maybe) sat is undefined variable or function. Note how in the second script, you define sat before calling the first script
sat = 'PG04';
date_initiale_extragere_automata;
I suggest that you change your first script into a function and pass in the sat as an input parameter. See function for more details.
As for
repmat('%f ',1,8)
it is replicating the '%f; character eight times (just try running this from the command line and also checking the documentation for repmat with doc repmat).
Related Question