converts the matrix, X into a string with a strX = num2str(X,format) format specified by the command. sprintf The table below shows how can be displayed in different formats with the sprintf command. Command Result Command Result 3e+00 3.142e+00 sprintf('% .0e \n',pi) sprintf('% .3e \n',pi) 3 3.1416 sprintf('% .0f \n',pi) sprintf('% .4f \n',pi) 3 3.14 sprintf('% .0g \n',pi) sprintf('% .3g \n',pi) line termination character. \n exponential notation (number to right of decimal point gives number of e digits displayed after the decimal point in the number). fixed-point notation (number to right of decimal point gives number of f digits displayed after the decimal point in the number). general notation: fixed-point or exponential notation, whichever is shorter g (number to right of decimal point gives the total number of digits displayed). e.g. = = 3.14159 X = pi strX num2str(X,'% .5f \n') Exercise 4 Open your m-script ex3.m and immediately save it as ex4.m. The m-script can be extended to annotate the graph of the sinusoidal function as shown in figure 1 with: Title with equation and numerical values for A and T. Axes labelled. Lines and text added to show amplitude and period. Numerical values displayed for angular velocity and frequency f. Fig. 2. Annotated plot of sinusoidal function of equation (3.1). The complete m-script ex4.m for figure 1 is at the end of this Chapter. Work through it line by line making sure you understand each part of the code. The handles to figure window elements are given by the prefix in the code. Change the program and h_ observe the figure window to test your understanding code. Data displayed on the graph and the plot window The way in which data is displayed on the graph is through the line properties. You can change the appearance of the plotted data using the following Matlab commands. Property Properties values (default)
strX = num2str(X,format) converts the matrix, X into a string with a format specified by the sprintf command. The table below shows how can be displayed in different formats with the sprintf command. Command Result Command Result sprintf('% .0e \n',pi) 3e+00 sprintf('% .3e \n',pi) 3.142e+00 sprintf('% .0f \n',pi) 3 sprintf('% .4f \n',pi) 3.1416 sprintf('% .0g \n',pi) 3 sprintf('% .3g \n',pi) 3.14 \n line termination character. e exponential notation (number to right of decimal point gives number of digits displayed after the decimal point in the number). f fixed-point notation (number to right of decimal point gives number of digits displayed after the decimal point in the number). g general notation: fixed-point or exponential notation, whichever is shorter (number to right of decimal point gives the total number of digits displayed). e.g. X = pi strX = num2str(X,'% .5f \n') = 3.14159 Exercise 4 Open your m-script ex3.m and immediately save it as ex4.m. The m-script can be extended to annotate the graph of the sinusoidal function as shown in figure 1 with: Title with equation and numerical values for A and T. Axes labelled. Lines and text added to show amplitude and period. Numerical values displayed for angular velocity and frequency f. Fig. 2. Annotated plot of sinusoidal function of equation (3.1). The complete m-script ex4.m for figure 1 is at the end of this Chapter. Work through it line by line making sure you understand each part of the code. The handles to figure window elements are given by the prefix h_ in the code. Change the program and observe the figure window to test your understanding code. Data displayed on the graph and the plot window The way in which data is displayed on the graph is through the line properties. You can change the appearance of the plotted data using the following Matlab commands. Property Properties values (default)