1

When using the tf function in matlab, I'm not getting exactly the output I need.

For example:

tf( 1 , [1 1 1])

Produces:

ans =

       1
 -----------
  s^2 + s + 1

Continuous-time transfer function.

What I desire is this:

 ans = 
    1/(s^2 + s + 1).

I do not want the pretty format. I want to access the transfer function directly.

TylerH
  • 20,799
  • 66
  • 75
  • 101

3 Answers3

1
f = tf( 1 , [1 1 1])

will return a TF object in f.

Bitwise
  • 7,577
  • 6
  • 33
  • 50
  • No, you dont understand. Doing what you said does me no good. Even with f = tf(1 , [1 1 1]), all I get is f = 1 ----------- s^2 + s + 1 I need f = 1/(s^2 + s + 1) – Luter Ferraz Feb 01 '13 at 20:44
  • @user2033840 do you want access to the actual transfer function or do you want it just displayed as 1/(s^2+s+1) ? – Bitwise Feb 01 '13 at 21:00
  • Just displayed as. I want a function or script that, when applied to said variable f = tf(1 , [1 1 1]), gives me the output 1/(s^2 + s + 1). Is there such a thing? Or anything similar? – Luter Ferraz Feb 01 '13 at 21:11
1

Modify printsys.m file in control toolbox. Remove disp([' ','-'*ones(1,len)]) line to remove the line and print nominator and dominator using single disp command.

Szymon Bęczkowski
  • 370
  • 1
  • 4
  • 9
1

I ran into the same problem and could not find a satisfactory solution, so I wrote my own.

It's very simple feel free to use it anyway you wish.

The following function should be placed in tf2string.m

% name: tf2string.m
% author: vittorio alfieri

% example:
% W1_out=tf2string(W1)
% 
% W1_out =
% (s + 37.0)/(1.646*s)

function output_string = tf2string(input_tf)

syms s

sym_num=poly2sym(input_tf.num{:},s);
sym_num=vpa(sym_num, 4);
char_num=char(sym_num);

sym_den=poly2sym(input_tf.den{:},s);
sym_den=vpa(sym_den, 4);
char_den=char(sym_den);

output_string = ['(', char_num, ')/(', char_den, ')'];
s=tf('s');

-Vittorio

vittorio88
  • 68
  • 6