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

2 views (last 30 days)
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)

Azzi Abdelmalek
Azzi Abdelmalek on 20 Jan 2014
Edited: Azzi Abdelmalek on 20 Jan 2014
Use plot before a legend
legend ({'NOON', 'BAT' , 'FLAT', 'Binomial'})
  3 Comments
Azzi Abdelmalek
Azzi Abdelmalek on 20 Jan 2014
Maybe you have used plot function as a variable in your code. Check this
clear plot
%plot your data
%Add legend
Bruno Pop-Stefanov
Bruno Pop-Stefanov on 20 Jan 2014
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.

Community Treasure Hunt

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

Start Hunting!