Professor Diomar Cesar Lobao

Universidade Federal Fluminense-Volta Redonda, RJ, Brasil

Diomar Cesar


Dept. Ciências Exatas - Exact Science Dept.

Search

splitstr.m

% example on splitting long format strings in Matlab fprintf statements

variable1 = 2;
variable2 = 4;
variable3 = 8;

% a usual short format string...

fprintf('v1: %f, v2: %f, v3: %f\n', variable1, variable2, variable3);

% a split, very long format string...

fprintf(['This is a long string that',...
         ' will have to be split!',...
         ' Here are the variables: ',...
         ' variable1: %f, variable2: %f,',...
         ' variable3: %f\n\n'], variable1,...
           variable2, variable3);

%
% Three things to note here:
%
% 1) to break up a long format string, you require the format string to
%    delimitted as ['format string'] instead of just 'format string'
%
% 2) you require a ",..." at the end of each split line
%
% 3) you can break up both the format string and the variable list
%
Skip to content