plot piecewise defined function

1 visualización (últimos 30 días)
Mina
Mina el 21 de Jun. de 2021
Comentada: Kiran Felix Robert el 24 de Jun. de 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 comentario
Kiran Felix Robert
Kiran Felix Robert el 24 de Jun. de 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 ?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Visual Exploration en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by