1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
function EcrireResultat()
%pour générer un nom de fichier test.txt:
nomFichier = sprintf('test1%d.txt');
%pour tester l'existence d'un fichier:
if resultat == fopen(nomFichier,'w','n','UTF-8');%Ouverture du fichier en lecture txt:On ouvre notre fichier en lecture seule et on vérifie l'ouverture
disp('fichier ouvert');
%ecrire dans le fichier resultat tous les vehicules sorties
n = numel(ListeVehsortie);
fprintf(resultat,'%s\n','nbr_veh_sorties=');
fprintf(resultat,'%i\t %i\t %i\n',n);
fprintf(resultat,'%s\n','horizon_simul=');
fprintf(resultat,'%i\t %i\t %i\n',Horizon);
for i=1:n
Veh = ListeVehsortie{i};
tt = numel(Veh.position); %obtenir le Nombre d'éléments
tt1= numel(Veh.vitesse);
tt2 = numel(Veh.acceleration);
fprintf(resultat,'%s\n','nbr_pas_temps=');
fprintf(resultat,'%i\t %i\t %i\n',tt);
Hentree = Veh.GetHeureEnt();
fprintf(resultat,'%s\n','heure_entree_veh=');
fprintf(resultat,'%i\t %i\t %i\n',Hentree);
if Hentree > 0
Hentree = Hentree - 1;
for t=Hentree:tt
position = Veh.GetPosition();
x = position(t);
vitesse = Veh.GetVitesse();
v = vitesse(t);
acceleration = Veh.GetAcceleration();
acc = acceleration(t);
if (~Hentree)
fprintf(resultat,'%i\t %i\t %i\n',x);
fprintf(resultat,'%i\t %i\t %i\n',v);
fprintf(resultat,'%i\t %i\t %i\n',acc);
fprintf(resultat,'%i\t %i\t %i\n',Hentree);
else
fprintf(resultat,'%i\t %i\t %i\n',x);
fprintf(resultat,'%i\t %i\t %i\n',v);
fprintf(resultat,'%i\t %i\t %i\n',acc);
fprintf(resultat,'%i\t %i\t %i\n',Hentree + 1);
end %for(t)
end%for(i)
end
end
save(monfichier)% Sauvegarde toutes les variables du workspace courant
fclose(resultat)
else
disp('impossible d''ouvrir le fichier');
end
end |
Partager