Programming and Data Types | ![]() ![]() |
Command/Function Duality
MATLAB commands are statements like
load help
Many commands accept modifiers that specify operands.
load August17.dat help magic type rank
An alternate method of supplying the command modifiers makes them string arguments of functions.
load('August17.dat') help('magic') type('rank')
This is MATLAB's command/function duality. Any command of the form
command argument
can also be written in the functional form
command('argument')
The advantage of the functional approach comes when the string argument is constructed from other pieces. The following example processes multiple data files, August1.dat
, August2.dat
, and so on. It uses the function int2str
, which converts an integer to a character string, to help build the filename.
for d = 1:31 s = ['August' int2str(d) '.dat'] load(s) % Process the contents of the d-th file end
![]() | String Evaluation | Empty Matrices | ![]() |