11.07.2015 Views

TP simulation à l'aide du logiciel MATLAB - LASC

TP simulation à l'aide du logiciel MATLAB - LASC

TP simulation à l'aide du logiciel MATLAB - LASC

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

g : la notation la plus compacte entre la notation à virguleflottante et la notation à virgule fixe est utilisée>> x = pi/3; y = sin(x);>> sprintf('sin(%8.6f) = %4.2f', x,y)ans =sin(1.047198) = 0.87>> sprintf('sin(%8.6f) = %4.2E', x,y)ans =exp(1.047198) = 8.66E-01>>4.4.3 Utilisations particulièresLa commande sprintf est vectorielle : si la variable n'est pas scalaire le format d'impression estréutilisé pour tous les éléments <strong>du</strong> tableau, colonne par colonne.>> x = [1 :10];>> sprintf(' %d ,',x)ans =1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ,>>Il est possible d'utiliser les symboles suivant dans les chaînes de caractères\n : provoque le passage à une nouvelle ligne\t : insère une tabulation horizontale\b : décale l'impression <strong>du</strong> champ suivant d'un caractère vers la gauche\r : saut horizontal>> z =[]; x = [1 :10]; for i=1 :length(x), z = [z ,x(i), log(x(i))]; end;>> s = sprintf('%4.1f | %8.6E \n ', z )ans =1.0 | 0.000000E+002.0 | 6.931472E-013.0 | 1.098612E+004.0 | 1.386294E+005.0 | 1.609438E+006.0 | 1.791759E+007.0 | 1.945910E+008.0 | 2.079442E+009.0 | 2.197225E+0010.0 | 2.302585E+00>>Si l'on a besoin d'afficher le caractère % on le doublera %% pour qu'il ne soit pas interprété comme ledébut d'un format. La commande fprintf est l'analogue de sprintf pour imprimer de variables selon unmodèle donné dans un fichier.28

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!