If statement to plot sections of simpsons 1/3 method only plots one area.
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!