Matlab 3D Plot
조회 수: 3 (최근 30일)
이전 댓글 표시
I want to plot two functions on the same 3D plot. X axis is Pa, Y axis is Pb, and Z axis is the value of each functions (Profit1 an Profit 3). I want to see dots (preferably different color) for each function's values based on different Pa and Pb combinations. So, it will be easy to navigate how these functions approach (or drift apart) based on Pa and Pb.
I attached the matlab file. My functions are Profit1 and Profit3.
Profit1 = (Pb*p-c)*Hb+Pa*(1-Pb)*wu*Ha;
Profit3 = Pa/(1-Pa)*(wu-w+Pb*(p-wu))*((1-Pa)*Ha+(1-Pb)*Hb)+w*(Pa*Ha+Pb*Hb)-c*(Ha+Hb);
Pa and Pb are probability values ranging 0 to 1, with 0.01 increment. I have the condition that Pa<Pb, always.
So,
Pb = 0:0.01:1
Pa = 0:0.01:(Pb - 0.01)
The constant values are:
c = 0;
p = 1;
wu = 0.8;
w = 0.5;
Ha = 100;
Hb = 200;
I tried to plot it but I want to know what 3D plot is the best in terms of easy navigation. I also wonder that if it is possible to plot this scenario on 2D.
Thank you in advance
댓글 수: 0
답변 (2개)
Geoff Hayes
2015년 9월 12일
Sd - try adding the following lines of code to the end your script (which runs just fine)
close all;
figure;
hold on;
Pa = 0:0.01:(Pb-0.01);
Pb = 0:0.01:0.50;
plot3(table(:,1),table(:,2),table(:,3),'Color','g');
plot3(table(:,1),table(:,2),table(:,4));
view(45,45);
Since Pa and Pb are in the first and second columns respectively of the table then we use these as the first two inputs to the plot3 function. The third parameter is just the Profit1 or Profit3.
댓글 수: 2
Hamoon
2015년 9월 12일
Actually there was no file there when I commented that, or maybe there was and I didn't see that. My comment was based on the question. So, Thank you Geoff.
Walter Roberson
2015년 9월 13일
Pb = 0:0.01:1
Pa = 0:0.01:(Pb - 0.01)
is going to give you a warning that the elements must be scalar. There is no way in MATLAB code arrays that have different numbers of columns depending on the row. You will need to loop over Pb and produce an output for each entry, or you will need to create a rectangular output and then arrange that the graphics is not produced for the places you do not want to see.
For example,
c = 0;
p = 1;
wu = 0.8;
w = 0.5;
Ha = 100;
Hb = 200;
Pb = 0 : 0.01 : 1;
Pa = 0 : 0.01 : 0.99;
[PB, PA] = ndgrid(Pb, Pa);
Profit1 = (PB*p-c)*Hb + PA.*(1-PB)*wu*Ha;
Profit3 = PA./(1-PA) .*(wu-w+PB*(p-wu)) .* ((1-PA)*Ha+(1-PB)*Hb) + w*(PA*Ha +PB*Hb) - c*(Ha+Hb);
unwanted = PA > PB;
subplot(1,3,1)
Results1 = Profit1;
Results1(unwanted) = NaN;
surf(PB, PA, Results1, 'EdgeColor', 'none');
title('Profit1')
subplot(1,3,2)
Results2 = Profit3;
Results2(unwanted) = NaN;
surf(PB, PA, Results2, 'EdgeColor', 'none');
title('Profit3')
subplot(1,3,3)
scatter3(PB(:), PA(:), Results2(:), 15, Results2(:)-Results1(:))
colorbar
title('Profit3 colored by difference to Profit1')
댓글 수: 2
Walter Roberson
2015년 9월 14일
편집: Walter Roberson
2015년 9월 14일
An example of looping:
c = 0;
p = 1;
wu = 0.8;
w = 0.5;
Ha = 100;
Hb = 200;
ax1 = subplot(1,2,1);
ax2 = subplot(1,2,2);
for Pb = 0 : 0.01 : 1;
Pa = 0 : 0.01 : Pb - 0.01;
Profit1 = (Pb*p-c)*Hb + Pa.*(1-Pb)*wu*Ha;
Profit3 = Pa./(1-Pa) .*(wu-w+Pb*(p-wu)) .* ((1-Pa)*Ha+(1-Pb)*Hb) + w*(Pa*Ha +Pb*Hb);
%
plot3(ax1, Pa, repmat(Pb,length(Pa),1), Profit1);
hold(ax1,'on');
plot3(ax2, Pa, repmat(Pb,length(Pa),1),Profit3);
hold(ax2,'on');
end
view(ax1,[169 18])
view(ax2,[169 18])
참고 항목
카테고리
Help Center 및 File Exchange에서 Polar Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!