How would i make line x vectors to be even to the rest. To form three different lines on the graph. Also how do you make the points show up with like a circle, square and x.
x = linspace(5,(-2*pi),(2*pi));
x1 = linspace((-2*pi),(2*pi),10);
x2 = linspace((-2*pi),(2*pi),20);
y = sin(x);
axis([-6, 6, 0, 1])
plot(x,y, 'r')
hold on
plot(x1,y, 'g')
hold on
plot(x2,y, 'p')
title('Plot Comparison of sin(x)')
xlabel('x values')
ylabel('sin(x)')
legend('5 points','10 points','20 points')

 채택된 답변

per isakson
per isakson 2020년 10월 25일
편집: per isakson 2020년 10월 25일

0 개 추천

The statement
x = linspace(5,(-2*pi),(2*pi));
looks strange to me. On R2018b it creates a row vector of length 6, which suprises me. Did you mean
x = linspace((-2*pi),(2*pi),5);
The two statements
plot(x1,y, 'g')
plot(x2,y, 'p')
will throw errors, since the length of x1 and y differs. They are 10 and 6, respectively. And the length of x2 and y also differs.
"to be even to the rest" you can do that with interp1, 1-D data interpolation (table lookup)
"points show up with like a circle, square and x" with 'o', 's' and 'x', see plot, 2-D line plot (and browse the entire page)

댓글 수: 3

Kalpha.mc
Kalpha.mc 2020년 10월 25일
Yes the second one was what i did first but i changed it to see if i could make it work. and i also have to make a plot of three lines with 5 points 10 points and 20 points. I just can't seem to figure out how to get the vectors to be the same. ( Also the lines to have a square, circles and * for the points on the lines)
per isakson
per isakson 2020년 10월 25일
편집: per isakson 2020년 10월 25일
I assume this is your homework. Am I right? Thus, I provide hints.
Regarding the markers, read the documentation on plot.
interp1 is most likely not what your teacher intended.
Kalpha.mc
Kalpha.mc 2020년 10월 25일
Its not how she would want it but it's okay i already figured it out. Thank You!

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

추가 답변 (0개)

카테고리

제품

릴리스

R2020a

태그

질문:

2020년 10월 25일

댓글:

2020년 10월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by