Having issues with plotting and supposedly there is a size problem?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Shao Qi
am 16 Mär. 2024
Kommentiert: Shao Qi
am 16 Mär. 2024
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 Kommentare
Akzeptierte Antwort
Dyuman Joshi
am 16 Mär. 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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!