Why a script doesn't work by itself and just included in another script?

1 visualización (últimos 30 días)
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!
  1 comentario
gblmtc
gblmtc el 25 de Mayo de 2018
I forgot to ask regarding the repmat('%f',1,8). I do not remember what the teacher told that it means. I do not understand the %f is cominf from. I look at the explanation regarding repmat on help but there is nothing about using the % . Thanks!

Iniciar sesión para comentar.

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 25 de Mayo de 2018
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).
  3 comentarios
Steven Lord
Steven Lord el 25 de Mayo de 2018
Later on in your code, you use that as the second input in a call to textscan, which in the documentation is referred to as formatSpec. When textscan tries to read data in from the file, that formatSpec tells MATLAB how it should try to interpret the file's data.
%f in a formatSpec means try to interpret the data as a double precision number. For more information on the formats available for use in a formatSpec, see the documentation to which I linked.
gblmtc
gblmtc el 25 de Mayo de 2018
Thank you Steve!
Very useful info ;). That's what I need, simple explanation to can make it clear in my mind.
Have a lovely day!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by