Error using plot Vectors must be the same length.

3 Ansichten (letzte 30 Tage)
Ariel Chou
Ariel Chou am 9 Dez. 2017
Kommentiert: Ariel Chou am 9 Dez. 2017
The question is:
Plot 2 curves in the same graph: y1=5*sin^2(u) and y2=5*cos^2(u), where u is in degrees from 0 to 180, with an increment of 1 degree.
Use the plot function which will show the label for F on the left side, and the label for G on the right side of the plot.
Label the horizontal axis as u (deg) and the vertical axes as F (kg) and G (kg).
Make a title: “Trigonometric Square Shapes”. Set the fontsize of title to be 14.
Specify the ‘xtick’ for u to be from 0 to 180 with an increment of 30. Finally, add the grid to figure(2).
I've finished the coding which is:
u = 0:1:180;
y1 = 5*(sin(u).^2);
y2 = 5*(cos(u).^2);
plot(x, y1, x, y2)
title('\fontsize{14}Trignometric Square Shapes')
grid on
xlabel('u (deg)')
xticks(0:30:180)
yyaxis left
ylabel('F (kg)')
yyaxis right
ylabel('G (kg)')
However, when I run it, an error appears
Error using plot
Vectors must be the same length.
How can I change my code to correct this error?

Antworten (1)

Walter Roberson
Walter Roberson am 9 Dez. 2017
plot(u, y1, u, y2)
  1 Kommentar
Ariel Chou
Ariel Chou am 9 Dez. 2017
Thank you haha. I forgot my x is actually u. I made a silly mistake.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by