Bird
0
0

Which of the following is the correct syntax to add a legend to a plot with two lines labeled 'Data1' and 'Data2'?

easy📝 Syntax Q12 of 15
MATLAB - 2D Plotting
Which of the following is the correct syntax to add a legend to a plot with two lines labeled 'Data1' and 'Data2'?
Alegend{'Data1', 'Data2'}
Blegend = ('Data1', 'Data2')
Clegend['Data1', 'Data2']
Dlegend('Data1', 'Data2')
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct legend syntax

    In MATLAB, the function legend is called with parentheses and string arguments to label plot lines.
  2. Step 2: Identify correct syntax

    The correct syntax uses parentheses and comma-separated strings: legend('Data1', 'Data2'). Other options use invalid assignment or brackets.
  3. Final Answer:

    legend('Data1', 'Data2') -> Option D
  4. Quick Check:

    legend('labels') uses parentheses [OK]
Quick Trick: Use legend('label1', 'label2') with parentheses [OK]
Common Mistakes:
  • Using assignment '=' instead of function call
  • Using square or curly brackets
  • Missing quotes around labels

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes