Having issues with plotting and supposedly there is a size problem?

7 views (last 30 days)
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?

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 16 Mar 2024
(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);

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!