MATLAB: How to display string with ↵ by multiple lines in command window

command windowmultiple lines in one celltable-function

Hi, I have a few transfer functions and some other numbers which I want to save to table and then display in command window. Transfer functions have 3 lines and It's apears by this ↵ characters. I need to remove them and show by 3 lines in one cell. For example:
tf_1 = tf(1.002, [0.578, 1], 'IODelay', 0.5);
tf_2 = tf(0.987, [0.578, 1], 'IODelay', 0.2);
tf_3 = tf(0.991, [0.612, 1], 'IODelay', 0.15);
tf_1_text = matlab.unittest.diagnostics.ConstraintDiagnostic.getDisplayableString(tf_1);
tf_2_text = matlab.unittest.diagnostics.ConstraintDiagnostic.getDisplayableString(tf_2);
tf_3_text = matlab.unittest.diagnostics.ConstraintDiagnostic.getDisplayableString(tf_3);
a = [0.9991, 0.897, 0.957];
b = {'a', 'b', 'c'};
transfer_fun_T = table([string(tf_1_text); string(a(1)); b(1)],...
[string(tf_2_text); string(a(2)); b(2)],...
[string(tf_3_text); string(a(3)); b(3)],...
'VariableNames', {'Transfer fun 1', 'Transfer fun 2', 'Transfer fun 3'},...
'RowName', {'Transfer function', 'some numbers', 'some strings'});
disp(transfer_fun_T);
Output of example code:
So I need a cell with multiple lines to make it readable.
Thank you for your answer

Best Answer

The table() display code changes newlines to ↵ as does the string() display code for non-scalar strings
SP = @(S) char(reshape(strsplit(char(string(S)), '\n'), [], 1));
tf_1 = tf(1.002, [0.578, 1], 'IODelay', 0.5);
tf_2 = tf(0.987, [0.578, 1], 'IODelay', 0.2);
tf_3 = tf(0.991, [0.612, 1], 'IODelay', 0.15);
tf_1_text = matlab.unittest.diagnostics.ConstraintDiagnostic.getDisplayableString(tf_1);
tf_2_text = matlab.unittest.diagnostics.ConstraintDiagnostic.getDisplayableString(tf_2);
tf_3_text = matlab.unittest.diagnostics.ConstraintDiagnostic.getDisplayableString(tf_3);
a = [0.9991, 0.897, 0.957];
b = {'a', 'b', 'c'};
transfer_fun_T = table({SP(tf_1_text); SP(a(1)); SP(b(1))},...
{SP(tf_2_text); SP(a(2)); SP(b(2))},...
{SP(tf_3_text); SP(a(3)); SP(b(3))},...
'VariableNames', {'Transfer fun 1', 'Transfer fun 2', 'Transfer fun 3'},...
'RowName', {'Transfer function', 'some numbers', 'some strings'});
disp(transfer_fun_T);
Transfer fun 1 Transfer fun 2 Transfer fun 3 ______________ ______________ ______________ Transfer function {6×34 char} {6×34 char} {6×34 char} some numbers {'0.9991' } {'0.897' } {'0.957' } some strings {'a' } {'b' } {'c' }
transfer_fun_T{'Transfer function', 'Transfer fun 1'}{1}
ans = 6x34 char array
' ' ' 1.002 ' ' exp(-0.5*s) * ----------- ' ' 0.578 s + 1 ' ' ' 'Continuous-time transfer function.'
Now what? We have managed to store the lines as individual rows within a cell array, but table() is not going to display those lines for you. To get it to display the individual lines, you would need to create individual rows within the table() object, like 'Transfer function (line 1)' which in turn would require worrying padding shorter variables to consistent number of rows...