plot piecewise defined function

2 ビュー (過去 30 日間)
Mina
Mina 2021 年 6 月 21 日
コメント済み: Kiran Felix Robert 2021 年 6 月 24 日
I am trying to plot a piecewise defined function using a filter, but im getting an error 'vectors must be the same length. The graph must have 20 points.
here is my code:
x = linspace(-10,10,20);
mask = x < 0;
y(mask) = 3* x(mask).^2 + 5*x(mask) - 7;
y(~mask) = 3*x(~mask) + 4;
figure(5);
plot(x, y,'--md','LineWidth',2,'MarkerFaceColor','g','MarkerEdgeColor','g');
title ('Plot Results of Mask');
xlabel ('-10 to 10 20 points');
ylabel ('Different for < 0 & >= 0');
grid on;
  1 件のコメント
Kiran Felix Robert
Kiran Felix Robert 2021 年 6 月 24 日
When I try to run your Code directly, without any changes. I do not see any error, rather I get a piecewise plot with 20 points.
x = linspace(-10,10,20);
mask = x < 0;
y(mask) = 3* x(mask).^2 + 5*x(mask) - 7;
y(~mask) = 3*x(~mask) + 4;
figure(5);
plot(x, y,'--md','LineWidth',2,'MarkerFaceColor','g','MarkerEdgeColor','g');
title ('Plot Results of Mask');
xlabel ('-10 to 10 20 points');
ylabel ('Different for < 0 & >= 0');
grid on;
Were to running a different script ?

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeVisual Exploration についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by