Hello i'm a bit desperate.
As nobody seemed to care about my last post i tried a lot on my problem but i still couldn't find the solution.
I want to use matlab2tikz to include my matlab figures into my latex document.
Since matlab2tikz is highly recommend by this community and many others i think the error must be in my code.
I simplified my matlab code a lot but i still wasn't able to find the error.
my matlab code for the figure:
example_data1 = linspace(0,100,5);
x1 = 1:length(example_data1);
y1 = example_data1;
x2 = 1:length(example_data1);
y2 = 2 * example_data1;
x3 = 1:length(example_data1);
y3 = 3 * example_data1;
Farbe1 = [0,1,0]*0.6; % darkgreen
Farbe2 = [1,0,0]*0.8; % darkred
Farbe3 = get(groot,'DefaultAxesColorOrder') % default values
Farbe3 = Farbe3(1,:); % default blue
figure(1)
% 3 axes
clf
%------------------------------------------------------------------
%-------------------------- plot1: ---------------------------
%------------------------------------------------------------------
a = plot(x1,y1,'green','LineWidth',2,'Color',Farbe1,...
'DisplayName','green plot')
ax1 = gca;
ax1.XLim = [0 length(x1)]
ax1.YLim = [0 max(y1)*1.5]
ax1.YTick = [0:25:300]
ax1.FontSize = 12;
%----------------------------------------------------------------
%-------------------------- plot2: --------------------------
%----------------------------------------------------------------
ax2 = axes('Position',ax1.Position);
b = plot(x2,y2,'blue','LineWidth',2,'Color',Farbe3,...
'DisplayName','blue plot')
ax2.Color = 'none';
ax2.XTick = [];
ax2.XLim = [0 length(x3)];
ax2.YAxisLocation = 'right';
ax2.FontSize = 12;
%----------------------------------------------------------------
%-------------------------- plot3: -------------------------
%----------------------------------------------------------------
ax3 = axes('Position',ax1.Position);
c = plot(x3,y3,'LineWidth',2,'Color',Farbe2,...
'DisplayName','red plot')
ax3.XTick = [];
ax3.YTick = [];
ax3.XLim = ax2.XLim;
ax3.YLim = ax2.YLim;
ax3.Color = 'none';
ax3.XAxisLocation = 'top';
ax3.YAxisLocation = 'right';
legend(ax3,[a,b,c])
% Run matlab2tikz
matlab2tikz('myfile.tex');
i need the three axes-objects to show more complicated data on two y-axes and also 2 x-axes.
The matlab code than leeds to this figure:

myfile.tex then looks like this for me:
% 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.
%
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
%
\begin{tikzpicture}
\begin{axis}[%
width=4.521in,
height=3.566in,
at={(0.758in,0.481in)},
scale only axis,
xmin=0,
xmax=5,
ymin=0,
ymax=150,
ytick={ 0, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300},
axis background/.style={fill=white}
]
\addplot [color=black!40!green, line width=2.0pt, forget plot]
table[row sep=crcr]{%
1 0\\
2 25\\
3 50\\
4 75\\
5 100\\
};
\end{axis}
\begin{axis}[%
width=4.521in,
height=3.566in,
at={(0.758in,0.481in)},
scale only axis,
xmin=0,
xmax=5,
xtick={\empty},
ymin=0,
ymax=200,
yticklabel pos=right
]
\addplot [color=mycolor1, line width=2.0pt, forget plot]
table[row sep=crcr]{%
1 0\\
2 50\\
3 100\\
4 150\\
5 200\\
};
\end{axis}
\begin{axis}[%
width=4.521in,
height=3.566in,
at={(0.758in,0.481in)},
scale only axis,
xmin=0,
xmax=5,
xtick={\empty},
ymin=0,
ymax=200,
ytick={\empty},
xticklabel pos=right,
yticklabel pos=right,
legend style={legend cell align=left, align=left, draw=white!15!black, fill=white!94!black}
]
\addplot [color=black!20!red, line width=2.0pt]
table[row sep=crcr]{%
1 0\\
2 75\\
3 150\\
4 225\\
5 300\\
};
\addlegendentry{red plot}
\end{axis}
\end{tikzpicture}%
I'm calling this file in a document:
\documentclass{article}
\usepackage{amsmath}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
\input{myfile.tex}
\end{document}
Compiling this document leads to this pdf with incomplete legend.
I've looked in the following questions for help but i think they don't fit to my problem.
overlap,
legend capture,
legend location,
Nobody before me seemed to have this problem even though it is very common to put a legend for three plots so i think there must be problem in my codes somewhere. But i can't think of any way to make it more simple cause i need these commands late for my figures.
Is matlab2tikz meant to be used different?
I also tried to solve the problem manually by editing the tikz-file. I noticed that only the last axis-enviroment has the \addlegendentry{red plot}. So i tried to put in the other axis-enviroments too. I also added the legend style={legend cell align=left, align=left, draw=white!15!black, fill=white!94!black} to theses axis-enviroments cause i want the legends to be in the same style. But this cause a lot of syntax errors unfortunately.
I gave up on this path cause a solution like this is a bit unsatisfying cause i want to use similar matlab-code on many plots and that would means i'd have to change it every time.
I hope somebody can help me this time. I don't know why last time nobody wanted to help. Maybe my question was unclear or the code was too complicated. I hope this time the question is more clear.
Any help on this would be appreciated.