Having issues with plotting and supposedly there is a size problem?
5 次查看(过去 30 天)
显示 更早的评论
So here is my code in plotting a graph.
x = linspace(-1,1);
y1 = 0.5 .* sin(sin(12.*x));
yyaxis left
plot(x,y1,'r-');
ylim([-.5,.5])
y2 = 15 .* (exp((2.*x)./5)) ;
yyaxis right
plot(x,y2,'b--');
ylim([10,24])
yyaxis left
title('Plots with different y axes')
xticks([-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1])
xlabel('x')
ylabel('y1')
yyaxis right
ylabel('y2')
But, supposedly variable x must be of [1 200] whatever that means however it is of size [1 100]. I am told that the number of points of vector x is wrong and I need to check the linspace. I dont understand the instructions given and if possible could someone help me clarify?
0 个评论
采纳的回答
Dyuman Joshi
2024-3-16
(I assume that you have written this code for an assignment, which requires the variable x to be of size [1 200], which should be mentioned somewhere in the problem description)
When you use that particular syntax of linspace (i.e. not specifying number of points to be generated), MATLAB creates an array of 100 evenly spaced points between the limits provided. (Refer to the documentation linked to see the syntax and its description).
You need to specify that you require n evenly spaced points between the given limits (n being 200 here) and for that use the second syntax available -
x = linspace(-1, 1, 200);
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!