How to format Multiple String with formatted data in MatLab? - compose -- MatLab
How to format Multiple String with formatted data in MatLab? - compose -- MatLab
compose command
[Description]
It can be used to format the escaped-character ('\') and formatted-character ('%')
Its style is very similar to its style of fprintf function.
e.g.
%compose
clear
clc
TXT = "The quick brown fox jumps";
TXT = TXT + '\n' + 'over the lazy dog.';
compose(TXT)
%{
"The quick brown fox jumps
over the lazy dog."
%}
fprintf("1\n");
F = "pi = %.5f";
%{
"pi = 3.14159"
%}
compose(F, pi)
fprintf("2\n");
F = "pi = %.2f, e = %.5f";
compose(F, [pi,exp(1)])
%{
"pi = 3.14, e = 2.71828"
%}
fprintf("3\n");
F = "real = %3.2f, imag = %3.2f";
A = [4+6i;2.3+5.7i;6.1+2i;0.5+7i];
%{
4×1 string array
"real = 4.00, imag = 6.00"
"real = 2.30, imag = 5.70"
"real = 6.10, imag = 2.00"
"real = 0.50, imag = 7.00"
%}
compose(F, [real(A),imag(A)])
fprintf("4\n");
F = 'The time is %d:%d';
A = [8,15,9,30;12,23,11,46];
compose(F,A)
%{
2×2 cell array
{'The time is 8:15' } {'The time is 9:30' }
{'The time is 12:23'} {'The time is 11:46'}
%}
fprintf("5\n");
more details on:
Comments
Post a Comment