Chart not re-setting axes correctly
조회 수: 2 (최근 30일)
이전 댓글 표시
I have code to generate a GUI that includes a chart. There is a callback function in the code that, based on changed input by the user, a new plot is created (it is a golf ball flight simulation). It all works correctly except that the axes of the first chart do not get cleared and so the numbers/values of the axes overlay each other and cannot be read! I have tried clearing the axes usin cla(ax) and setting the axes limits using the current minima and maxima. Nothing has worked yet (including taking hold on and off). Here is the troublesome code snippet
ax = axes('Units','pixels','Position',[350 70 500 300]);
% axes(ax) ;
cla(ax,'reset')
cla(ax) ;
xmax = round(max(x_vals)) + 1 ;
xmin = min(x_vals) ;
ymax = round(max(z_vals)) + 1 ;
ymin = min(z_vals) ;
xlim([xmin xmax])
ylim([ymin ymax])
plot(x_vals, z_vals, 'g', 'LineWidth', 2.0);
axis equal
hold on;
% hold off
yline(0, 'k--', 'LineWidth', 1.5); % ground line
title('Trajectory of a golf ball (wind, temperature, humidity, spin decay included)');
xlabel('Horizontal Distance (m)');
ylabel('Vertical Distance (m)');
grid on;
legend('Trajectory');
msg = sprintf('Carry distance (y) %.1f% \n ', carry_distance);
set(resultLabel_1, 'String', msg);
msg = sprintf('Apex (m) %.2f% \n ', max_height);
set(resultLabel_2, 'String', msg);
msg = sprintf('Land angle (deg) %.2f% ', land_angle);
set(resultLabel_3, 'String', msg);
% msg = sprintf('Carry distance (y) %.1f% \nApex (m) %.2f% \nLand angle (deg) %.2f% ', carry_distance, max_height, land_angle);
% set(resultLabel, 'String', msg);
Any help would be most appreciated!
Cheers,
Rob
댓글 수: 3
Matt J
2025년 6월 16일
I can't see any problem in the code as shown. You'll have to attach a simplified .mlapp file which reproduces the issue.
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!