Instead of doing all that, you can use LaTeX to change the color of the legend text. Let's take a simple example.
x = [1 2 3 4];
y = [2 4 6 8];
z = [2 3 4 5];
plot(x, y, x, z);
legend('{\color{green}y vs x}', '{\color{blue}z vs x}');
This would give you the following graph.
You can even have multiple colors in the same text. For instance.
legend('{\color{green}C}{\color{red}O}{\color{orange}L}{\color{black}O}{\color{gray}R}', '{\color{blue}z vs x}');
The above would give you the following graph.
Hope this helped. :)