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
|
% Choix du fichier de données à utiliser :
FichierTexte = 'Exemple.txt'
% Choix du nom du fichier de sortie :
FichierSortieP1='Exemple_P1.txt'
FichierSortieP2='Exemple_P2.txt'
% Ouverture du fichier texte dans lequel il y a les données.
fid=fopen(FichierTexte,'r');
% Lecture d'un texte formaté.
m=textscan(fid,'%f %f %f %f','delimiter','\t');
% Fermeture du fichier après lecture.
fclose(fid);
Col1=m{1}; % La colonne 2 de ma matrice m contient les mois "MM".
Col2=m{2}; % La colonne 5 de ma matrice m contient la hauteur significative spectrale "Hm0".
Col3=m{3}; % La colonne 6 de ma matrice m contient la direction moyenne de provenance de la houle "Dmoy".
Col4=m{4}; % La colonne 9 de ma matrice m contient la période moyenne "t02".
% Je compose la matrice "Matrice" avec laquelle je veux travailler à partir des
% colonnes précédemmment extraites du fichier texte.
Matrice = horzcat (Col1, Col2, Col3, Col4);
Dlig=length(Matrice)
% Je créé les matrices P1 et P2.
for lig = 1:Dlig
if Col1(lig,:) == 7
elseif Col1(lig,:) == 8
elseif Col1(lig,:) == 9
P1 = Matrice(: , :)
else
P2 = Matrice(: , :)
end
end
% Création du fichier de sortie.
FichierP1=fopen(FichierSortieP1,'w');
FichierP2=fopen(FichierSortieP2,'w');
% Ecriture dans le fichier de sortie.
fprintf(FichierP1,' %12.2f %12.2f %12.2f %12.2f/n ',P1);
fclose(FichierP1);
fprintf(FichierP2,' %12.2f %12.2f %12.2f %12.2f/n ',P2);
fclose(FichierP2); |
Partager