4 M-Files
4 M-Files
Script files can be typed and edited in any text editor and then
pasted into the MATLAB editor
Example
Cont.. .
With the fprintf command it is possible to start a new line in the
middle of the string.
This is done by inserting \n before the character that will start the
new line
Character Description
– (minus sign) : Left-justifies the number within the field
+ (plus sign) : Prints a sign character (+ or –) in front of the
number
0 (zero) : Adds zeros if the number is shorter than the
field
Here are some examples of flags in use:
Note!!
With the fprintf command it is possible to insert more than one number
(value of a variable) within the text
fprintf (‘..text...%g...%g...%f...’,variable1,variable2,variable3)
Additional remarks !!!
To place a single quotation mark in the displayed text, type two
single quotation marks in the string inside the command
variable_name = xlsread(‘filename’)
When an Excel file has several sheets, the xlsread command can
be used to import data from a specified sheet
variable_name = xlsread(‘filename’,‘sheet_name’)
Cont.. .
o Another option is to import only a portion of the data that is in
the spreadsheet. This is done by typing an additional argument in
the command
variable_name = xlsread(‘filename’,‘sheet_name’,‘range’)
xlswrite(‘filename’,variable_name)
The file must be in the current directory. If the file does not
exist, a new Excel file with the specified name will be created
Cont.. .
variable_name is the name of the variable in MATLAB
with the assigned data that is being exported