plot piecewise defined function
1 view (last 30 days)
Show older comments
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 Comment
Kiran Felix Robert
on 24 Jun 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 ?
Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!