How to plot 3D ?

2 次查看(过去 30 天)
Ynne
Ynne 2018-2-13
评论: Ynne 2018-2-14
I want to use this below mentioned code to plot the distributions in 3D format, how can i fix it?
x = -6:0.01:6;
rho = [1 1.5 2 4 10];
p = [];
for k = 1:length(rho)
p = [p exp(-abs(x').^rho(k)) / (2*gamma(1+1/rho(k)))];
end
figure, hold on; set(gca,'fontsize',14);
plot(x,p,'linewidth',2);
str = num2str(rho');
clear str2;
for k = 1:length(rho)
str2(k,:) = ['\it\rho =' str(k,:)];
end
legend(str2); xlabel('\itx'); ylabel('\itGG(x\rm;\it\rho)'); xlim([-6 6])

回答(1 个)

Hossam Selim
Hossam Selim 2018-2-13
Hi, what you are doing now is you apply the math to respective elements. however, in order to apply the math for all the combinations of elements in x and rho vectors. you need to use meshgrid and surf functions for making the plot you want. have a look at the modified code below. Hope this helps.
x= -6:0.01:6;
rho = [1 1.5 2 4 10];
[X,Y]=meshgrid(x,rho);
p = [exp(-abs(X).^Y) ./ (2*gamma(1+1./Y))];
figure
surf(X,Y,p);
  1 个评论
Ynne
Ynne 2018-2-14
Thanks a lot.
But i want to have a 3D distribution for each rho, is this possible ?

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by