Chart not re-setting axes correctly
1 view (last 30 days)
Show older comments
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 Comments
Matt J
on 16 Jun 2025
I can't see any problem in the code as shown. You'll have to attach a simplified .mlapp file which reproduces the issue.
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Graphics Object Programming 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!