Legend Error. Need Help ASAP. Why is the error coming? What am I doing wrong?

x = 1:1:6;
>> y1 = x.^2;
>> y2 = (x.*(x+2))/2;
>> y3 = (x.*(x+2))/3;
>> y4 = x;
>> legend ('NOON', 'BAT' , 'FLAT', 'Binomial');
Warning: Plot empty.
> In legend at 286
>> plot (x, y1, x, y2, x, y3, x, y4);
>> legend ('NOON', 'BAT' , 'FLAT', 'Binomial');
Warning: Plot empty.
> In legend at 286
>>

Answers (1)

Use plot before a legend
legend ({'NOON', 'BAT' , 'FLAT', 'Binomial'})

3 Comments

>> x = 1:1:6;
>> y1 = x.^2;
>> y2 = (x.*(x+2))/2;
>> y3 = (x.*(x+2))/3;
>>
>> y4 = x;
>> plot (x, y1, x, y2, x, y3, x, y4);
>> legend ({'NOON', 'BAT' , 'FLAT', 'Binomial'});
Warning: Plot empty. > In legend at 286 >>
Still the same error
Maybe you have used plot function as a variable in your code. Check this
clear plot
%plot your data
%Add legend
I ran this code and I get the plot with no error. Execute the following to clear previous variables or plots before running your code:
clear all
close all
clc

Sign in to comment.

Asked:

on 20 Jan 2014

Commented:

on 20 Jan 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!