Error using plot Vectors must be the same length.

조회 수: 3 (최근 30일)
Ariel Chou
Ariel Chou 2017년 12월 9일
댓글: Ariel Chou 2017년 12월 9일
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?

답변 (1개)

Walter Roberson
Walter Roberson 2017년 12월 9일
plot(u, y1, u, y2)
  댓글 수: 1
Ariel Chou
Ariel Chou 2017년 12월 9일
Thank you haha. I forgot my x is actually u. I made a silly mistake.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by