Hola chic@, ocupo ayuda con un problema. Estoy intentando graficar con scartter3 dos figuras en un solo Axies en App designer. sin embargo, consigo un resultado en 2D.

3 次查看(过去 30 天)
Inicialemente programe sobre un .mlx y funciona de maravilla me muestra la grafica en 3D con todos las dos figuras que requiero. No obstante a la hora de querer reflejar esto en App designer no consigo un resultado en 3D y adiconal a eso como le doy correr a la App me genera una figura 2 la cual si muestra los 3 ejes pero esta complemente vacia. Cabe resaltar que en el App designer en multiple plots en el apartado nextplot elegí add, antes de hacerlo si me arrojaba una grafica en 3D pero unicamente de una figura, yo requiero tener las dos en ese solo Axies.
CODE .mlx ---> funciona de maravilla ahí
figure('Name','Proyección Multidimencional')
scatter3(score(1:212,1),score(1:212,2),score(1:212,3),'blue',"+")
hold on
view(3);
scatter3(score(213:569,1),score(213:569,2),score(213:569,3),'magenta',"*")
xlabel('1st Principal Component')
ylabel('2st Principal Component')
zlabel('3st Principal Component')
hold off
CODE en el App designer
scatter3(app.UIAxes,score(1:212,1),score(1:212,2),score(1:212,3),'blue',"+")
hold on
view(3)
scatter3(app.UIAxes,score(213:569,1),score(213:569,2),score(213:569,3),'magenta',"*")
hold off
De ante mano muchas, gracias.

回答(1 个)

Vidhi Agarwal
Vidhi Agarwal 2024-5-20
Hi Juan Diego Polo Martinez,
I understand that you are facing issues while plotting multiple 3D graphs on the same axes in App Designer.
Following are the troubleshooting steps that might help you to resolve the issue:
  • Ensure score is Accessible: First, confirm that the score array is accessible within the scope of the function where you're attempting to plot. If the score is calculated or loaded outside of the App Designer callback or function where the plotting occurs, make sure it's passed correctly to this scope.
  • Check for Errors or Warnings: Ensure there are no runtime errors or warnings that might indicate an issue with the data or the plotting commands. Sometimes, if there's an issue with the data dimensions or values, MATLAB might fail silently or log a warning.
  • Use hold (app.UIAxes, 'on') Syntax: When working in App Designer, it's recommended to use the full syntax for hold on and hold off to ensure clarity on which axes you're targeting. This might look redundant but can help avoid issues in some contexts.
hold (app.UIAxes, 'on');
% Your plotting commands here
hold (app.UIAxes, 'off');
  • Explicitly Set the View: You've included view (3) which sets the axes to a 3D view. Ensure this command is applied to “app.UIAxes” specifically. If not explicitly set, MATLAB might not apply the 3D view to the intended axes.
view (app.UIAxes, 3); % Sets the 3D view on app.UIAxes
  • Confirm Axes Properties: Double-check that “app.UIAxes hasn't had its properties (like Visible, XLim, YLim, ZLim, etc.) inadvertently modified elsewhere in your app that could affect the visibility of your plots.
  • Debugging the Empty Figure: If you're seeing an empty figure window popping up alongside your app, it suggests that somewhere in your code (or possibly in callbacks you haven't shown) a figure command or another plotting command targeting a new figure is being executed. Ensure all plot commands are directed at app.UIAxes and that no stray figure commands are present.
  • Redrawing or refreshing the UIAxes: Sometimes, forcing a redraw of the axes after plotting can help, especially after complex updates.
drawnow; % Forces MATLAB to perform figure window updates at once
Here's how your plotting code might look with these considerations:
% Ensure 'score' is accessible here
scatter3(app.UIAxes, score(1:212,1), score(1:212,2), score(1:212,3), 'blue', "+");
hold(app.UIAxes, 'on'); % Ensure we're holding the correct axes
view(app.UIAxes, 3); % Explicitly set the 3D view on app.UIAxes
scatter3(app.UIAxes, score(213:569,1), score(213:569,2), score(213:569,3), 'magenta', "*");
xlabel(app.UIAxes, '1st Principal Component');
ylabel(app.UIAxes, '2nd Principal Component');
zlabel(app.UIAxes, '3rd Principal Component');
hold(app.UIAxes, 'off'); % Release the hold

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by