If statement to plot sections of simpsons 1/3 method only plots one area.

1 view (last 30 days)
I'm currently designing a GUI in matlab and I need to plot the areas of iteration using the simpson's 1/3 method. The problem is, every time I go to plot the areas, only one iteration of the method get's plotted. When I was developing the code in a normal function, I would have to click run twice in order to plot all the areas. How can I fix this so it plots everything in one go?
if app.MethodEditField.Value == 3 % Simpsons 1/3
% Simpsons 1/3
if rem(length(x), 2) == 0
%Display error lamp
app.RedincompatableamountofdatapointsLamp.Color = [1 0 0];
else
% define starting values
Area = 0;
b = 0;
% create for loop to pull from the given data points
for i = 1:2:length(y)-2
I(b+1) = b;
A(b+1) = Area;
% define deltax
v = x(i+2)-x(i);
% add the area to itself along the for loop
Area = Area + ((y(i)+4*y(i+1)+y(i+2))/6)*v;
b = b + 1;
% end the for loop
end
% Final I and A values
I(b+1) = b;
A(b+1) = Area;
Area = num2str(Area);
app.AreaEditField.Value = Area;
hold on % Start graphing
%figure(app.UIAxes_2) % Call figure 1
plot(app.UIAxes_2,I,A,"-",'LineWidth',2,'Color',[0 0 0]) % Plot area per iteration
title(app.UIAxes_2,'Area Increase Per Simpsons 1/3 Area') % Title figure 1
xlabel(app.UIAxes_2,'Iteration') % Label x Axis
ylabel(app.UIAxes_2,'Area') % Label y Axis
end
plot(app.UIAxes_3,x,y,"-",'LineWidth',2,'color',[0 0 0]) %plot function
title(app.UIAxes_3,'Simpsons 1/3 Integration Method') % Title plot
xlabel(app.UIAxes_3,'x') % Label x axis
ylabel(app.UIAxes_3,'y') % Label y axis
%figure(app.UIAxes_3) %call second figure
for i = 1:2:length(x)-2 %for loop to
% Plot the polygon
plot(app.UIAxes_3, polyshape([x(i),x(i+1),x(i+2),x(i+2),x(i)],[y(i),y(i+1),y(i+2),0,0]))
hold on
end
hold off
end

Answers (1)

Rik
Rik on 1 Apr 2023
Without explicit handles, most graphics functions revert to the normal figures. You should try providing the handle to your uiaxes, or set its nextplot property directly.

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!