Chart not re-setting axes correctly

2 vues (au cours des 30 derniers jours)
Robert
Robert le 16 Juin 2025
Réponse apportée : Robert le 16 Juin 2025
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 commentaires
Robert
Robert le 16 Juin 2025
Hi Matt, thanks for your comment. I have tried removing the hold on and tried using hold off later in the code segment. Neither had any effect on the axes issue
Matt J
Matt J le 16 Juin 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.

Connectez-vous pour commenter.

Réponse acceptée

Robert
Robert le 16 Juin 2025
Matt, here is the entire script file. It should run (I do not believe there are any additional functions/subroutines that are not part of the script file). When you run the script, a GUI will appear and default values for the variables are populated. If you hit "Estimate & Plot", the chart will be generated. The axes will look perfect. If you then, alter one of the varialbes (e.g., change ball speed from 70 mph to 120 mph for example), then hit "Estimate & Plot" again you will notice that the chart is created but the axes are illegible! On the chart, updated numbers for Carry distance, Apex and Land angle appear in the bottom left region of the GUI.
Thanks again for any assistance you can provide! It has been frustrating (spent way too many hours on it already!).
Cheers,
Rob

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Programming dans Help Center et File Exchange

Produits


Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by