MATLAB: How to solve “Line cannot be a child of Figure.” error

3d plotsMATLABplot

So, I have a problem trying to plot 2 points in a 3D graph. I'm using the following code:
fig_UPS = figure;
hold on
plot3(fig_UPS, handles.VolDensPot_UPS, handles.PesoDensPot_UPS, handles.Rend_UPS, 'Color', 'r', 'Marker', '*','DisplayName', handles.Nome_UPS, 'LineStyle', 'none');
hold on
plot3(fig_UPS, handles.VolDensPot_Wendell, handles.PesoDensPot_Wendell, handles.Rend_Wendell, 'Color', 'b', 'Marker', 'o','DisplayName', handles.Nome_Wendell, 'LineStyle', 'none');
legend(fig_UPS);
xlabel(fig_UPS, 'Densidade de Potência Volumétrica [kW/dm³]');
ylabel(fig_UPS, 'Densidade de Potência Mássica [kW/kg]');
zlabel(fig_UPS, 'Rendimento')
But I've being getting the "Line cannot be a child of Figure." error.
How can I solve this?
Thanks in advance

Best Answer

You need to create an axes object first so you can use that as the parent object instead.
fig_UPS = figure;
ax=axes('Parent',fig_UPS);
hold(ax,'on')
plot3(ax, handles.VolDensPot_UPS, handles.PesoDensPot_UPS, handles.Rend_UPS, 'Color', 'r', 'Marker', '*','DisplayName', handles.Nome_UPS, 'LineStyle', 'none');
plot3(ax, handles.VolDensPot_Wendell, handles.PesoDensPot_Wendell, handles.Rend_Wendell, 'Color', 'b', 'Marker', 'o','DisplayName', handles.Nome_Wendell, 'LineStyle', 'none');
legend(ax);
xlabel(ax, 'Densidade de Potência Volumétrica [kW/dm³]');
ylabel(ax, 'Densidade de Potência Mássica [kW/kg]');
zlabel(ax, 'Rendimento')