legend color is not match
Show older comments
hi,guys,
my code is to plot 3 sets of data,in blue ,red and green respectively, however, the legend is not match for the third one (it is the same with the 2rd one), can anyone help me?
--------------------------------------------------------------------------------------------------
clear
filename = '1.log';
set = 768;
fid = fopen(filename,'r');
[num1,num2] = textread(filename,'%d%d');
lines = get_lines(fid);
length = 1:1:lines;
title('haha');
xlabel('hehe');
ylabel('heihei');
plot(length,num1,'-b*',length,set,'-r',length,num2,'-go');
hleg = legalpha('1','2','3');
fclose('all');
the results:

Accepted Answer
More Answers (1)
length,set,'-r'
in your plot instruction will not give what you want.
you should use
[1 lines], [set set], '-r'
instead because your x and y must have the same number of values to be a single line plot rather than hundreds of individual plots.
Incidentally, don't call a variable 'length'. There is a function called length and even if it doesn't cause you problems here it is sure to in the future if you hide the function name under a variable name.
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!