MATLAB: Fprintf Multiple Lines

command windowdisplayfprintflinesmultipleprint

Is there a way to print multiple lines to the command window (like fprintf does for single lines) without using fprintf at the start of each line?
At the moment my code looks similar (the below was quickly made up as an example) to;
fprintf ('The results of test %d are such that %d ', t1, cats)
fprintf ('of the cats are older than %d years old.\n', age)
fprintf ('The results of test %d are such that %d ', t2, dogs)
fprintf ('of the dogs are older than %d years old.\n', age)
fprintf ('The results of test %d are such that %d ', t3, fish)
fprintf ('of the fish are older than %d years old.\n', age)
Is there a way to only state fprintf once at the start then have the text followed by the variables at the end? Maybe a bit like;
fprintf ('The results of test %d are such that %d of the ...
cats are older than %d years old.\nThe results of test ...
%d are such that %d of the dogs are older than %d years ...
old.\nThe results of test %d are such that %d of the ...
fish are older than %d years old.\n', t1, cats, age, ...
t2, dogs, age, t3, fish, age)
I've searched the help files and looked into sprintf but I couldn't see anything that does this so thought I'd see if I'm wasting my time searching!
The help is much appreciated, and apologise if I've missed something staring me in the face in the help files!

Best Answer

Yes, that second syntax for fprintf() itself is fine. You are being caught on the fact that string constants cannot be continued by using ...
fprintf( ['The results of test %d are such that %d of the ', ...
'cats are older than %d years old.\nThe results of test ', ...
'%d are such that %d of the dogs are older than %d years ', ...
'old.\nThe results of test %d are such that %d of the ', ...
'fish are older than %d years old.\n'], t1, cats, age, ...
t2, dogs, age, t3, fish, age);