MATLAB: 3D Plot with Four Variables

3d plot - variables -

Hello, I have four variables (Demand, NPV_all, STD_all, STD_In) and I would like to plot them in a 3D plot. I have created the plot but for some reason I can not show the legend. Can anyone help please.
if true
Demand = rand(7,3);
NPV_all = rand(7,3);
STD_all = rand(7,3);
STD_In = [0.25 .5 .75] .* ones(7,3);
Demand_V = Demand(:);
NPV_V = NPV_all(:);
STD_V = STD_All(:);
STD_In_V = STD_In(:);
h = scatter3(Demand_V,STD_V,NPV_V,markerSize,STD_In_V,'filled');
title('Economic Impact of Production Profile')
xlabel('Demand [MMSCFD]')
ylabel('STD [$B]')
zlabel('NPV [$B]')
legend('STD = 0.25', 'STD = 0.50','STD = 0.75');
end

Best Answer

Demand = rand(7,3);
NPV_all = rand(7,3);
STD_all = rand(7,3);
STD_In = [0.25 .5 .75] .* ones(7,3);
Demand_V = Demand(:);
NPV_V = NPV_all(:);
STD_V = STD_all(:);
STD_In_V = STD_In(:);
markerSize = 10 ;
STD = [0.25 0.50 0.75] ;
figure
hold on
for i = 1:length(STD)
idx = abs(STD_In_V-STD(i))<=10^-3 ;
h = scatter3(Demand_V(idx),STD_V(idx),NPV_V(idx),markerSize,STD_In_V(idx),'filled');
end
title('Economic Impact of Production Profile')
xlabel('Demand [MMSCFD]')
ylabel('STD [$B]')
zlabel('NPV [$B]')
legend('STD = 0.25', 'STD = 0.50','STD = 0.75');