Mar 7, 2025
fprintf
in MATLABfprintf
.numcats
: 7favcat
: "floozy"fprintf
fprintf('Of my %g cats, %s is my favorite.\n', numcats, favcat);
%g
: Used for inserting numbers (formats as integer here).%s
: Used for inserting text strings.\n
: New line character to end the sentence.cats = {'floozy', 'cocoanut', 'upchuck', 'boom boom', 'doodle', 'Neptune', 'murky'};
{}
to extract text from a cell array.fprintf('My cat''s name is %s\n', cats{4});
''
for apostrophes.fprintf
on entire cell arrays without specifying elements causes errors.fprintf('My cat''s name is %s\n', cats);
results in error.:
operator.fprintf('My cat''s name is %s\n', cats{1:length(cats)});
fprintf
fprintf
. More details about table creation in the next lecture.