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

조회 수: 1 (최근 30일)
MATLABC
MATLABC 2023년 3월 30일
답변: Rik 2023년 4월 1일
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
  댓글 수: 2
Rajeev
Rajeev 2023년 3월 31일
Can you try removing the hold off statement from the second last line?
MATLABC
MATLABC 2023년 3월 31일
It still only shows one iteration of the for loop :/

댓글을 달려면 로그인하십시오.

답변 (1개)

Rik
Rik 2023년 4월 1일
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.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by