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

8 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 2 de En. de 2021
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...
  3 comentarios
Walter Roberson
Walter Roberson el 3 de En. de 2021
table() objects are designed for computation, not for display purposes.
Report Generator gives much more flexibility on display of tables.
So there is no way to display table with transfer functions?
[P,Q] = tfdata(tf_1);
"(" + string(vpa(poly2sym(P{1}, S),5)) + ")/(" + string(vpa(poly2sym(Q{1}, S),5)) + ")"
and use hasdelay(tf_1) to determine whether to construct "exp(" + -total_delay(tf_1) + "*s)*" as a prefix.
Jan Brieznik
Jan Brieznik el 3 de En. de 2021
Report generator sounds good for my result for my problem thank you.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by