So, I use the following MATLAB code:

sys1 = rss(3);
sys2 = rss(3);
h = stepplot(sys1,sys2);

As an example of what I'm trying to do. This gives me the following plot of my step response (great):

How it should appear in my document

I generate the Tikz code using matlab2tikz, save it in the directory and call it by (and this is what it ends up looking like):


How the plot appears in my document

Those two 'asymptotes' (they aren't really) go on for enter image description here... so that is where the problem lies. How do avoid this happening/fix it?


Open the .tex file and move/remove some lines (shown in code comments).

% This file was created by matlab2tikz.
%The latest updates can be retrieved from
%  http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz-matlab2tikz
%where you can also make suggestions and rate matlab2tikz.

scale only axis,
separate axis lines,
every outer x axis line/.append style={white!40!black},
every x tick label/.append style={font=\color{white!40!black}},
every x tick/.append style={white!40!black},
xlabel={Time (seconds)},% add
every outer y axis line/.append style={white!40!black},
every y tick label/.append style={font=\color{white!40!black}},
every y tick/.append style={white!40!black},
ylabel={Amplitude},% add
axis background/.style={fill=white}, 
title style={font=\bfseries},%add
title={Step Response}%add
\addplot [color=mycolor1, forget plot]
  table[row sep=crcr]{%
0   0\\
0.0351168993205545  -0.156490938637001\\
0.070233798641109   -0.302010946222257\\
0.105350697961664   -0.433803246272174\\
0.140467597282218   -0.550050238976298\\
% ... data1
6.91802916614924    -1.13313393941205\\
6.95314606546979    -1.13315926459507\\
6.98826296479035    -1.13318373307777\\
%change value
%70233798641.109    -1.1338824802173\\
25  -1.1338824802173\\


%\addplot [color=black, dotted, forget plot]
%  table[row sep=crcr]{%
%-1e+99 -1.1338824802173\\
%-1e+96 -1.1338824802173\\
%-1e+93 -1.1338824802173\\
% ...
%1e+96  -1.1338824802173\\
%1e+99  -1.1338824802173\\

\addplot [color=mycolor2, forget plot]
  table[row sep=crcr]{%
0   0.949221831131023\\
0.140808864813683   0.976722525638425\\
0.281617729627366   0.980443252277657\\
% ... data2
21.9661829109345    1.34145327046453\\
22.1069917757482    1.34146698687354\\
22.2478006405619    1.34148008594245\\
22.3886095053756    1.34149259545615\\
%change value
%225294183701.893   1.34175802934311\\
25  1.34175802934311\\

% delete
%\addplot [color=black, dotted, forget plot]
%  table[row sep=crcr]{%
%-1e+99 1.34175802934311\\
%-1e+96 1.34175802934311\\
%-1e+93 1.34175802934311\\
% ...
%1e+93  1.34175802934311\\
%1e+96  1.34175802934311\\
%1e+99  1.34175802934311\\

%delete/remove to first axis

%scale only axis,
%xlabel={Time (seconds)},
%axis line style={draw=none},
%title style={font=\bfseries},
%title={Step Response},
%axis x line*=bottom,
%axis y line*=left

There is another solution, if someone has the same problem. You first have to run


before you run


The first script will delete some unnecessary information off the figure. After executing the second script you can open the generated file and edit it (legend, label, axis, etc.).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.