plot piecewise defined function

1 visualizzazione (ultimi 30 giorni)
Mina
Mina il 21 Giu 2021
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 Commento
Kiran Felix Robert
Kiran Felix Robert il 24 Giu 2021
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 ?

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Visual Exploration in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by