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

6 ビュー (過去 30 日間)
Shao Qi
Shao Qi 2024 年 3 月 16 日
コメント済み: Shao Qi 2024 年 3 月 16 日
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?

採用された回答

Dyuman Joshi
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 件)

カテゴリ

Help Center および File Exchange2-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