フィルターのクリア

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

2 ビュー (過去 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 Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by