I would like to change multiplier term from 1 to 50 with a step of 1 and plot all the shaded area by stacking all the cases up in z axis. Different cases could have different shaded area color to distinguish.
clc
clear
x(1) = 0 ;
y(1) = 0 ;
multiplier = 50 ;
for i = 1 : 1 : 99
x(i+1) = i^2 ;
y(i+1) = multiplier * i ;
end
iv = 1:numel(x);
Lv = x <= y;
hold on
figure(1)
plot(x)
hold on
plot(y)
patch([iv(Lv) flip(iv(Lv))], [x(Lv) flip(y(Lv))], 'g')
grid on

댓글 수: 3

Dyuman Joshi
Dyuman Joshi 2023년 9월 28일
"plot all the shaded area by stacking all the cases up in z domain."
What is the manner of stacking?
Can you give an exaple of how the output should look like?
Aditya Zade
Aditya Zade 2023년 9월 28일
편집: Aditya Zade 2023년 9월 28일
The shaded area may look something like this. The semicircular area would get narrower as multiplier becomes low.
Aditya Zade
Aditya Zade 2023년 9월 28일
I have plotted for two cases when multiplier = 40 and 50, but have done in only xy axes.

댓글을 달려면 로그인하십시오.

 채택된 답변

Star Strider
Star Strider 2023년 9월 28일
clc
clear
x(1) = 0 ;
y(1) = 0 ;
zm = NaN(2,200);
multiplier = 50 ;
figure(1)
hold on
for i1 = 1:2
multiplier(i1) = 40 + 10*(i1-1);
for i = 1 : 1 : 99
x(i+1) = i^2 ;
y(i+1) = multiplier(i1) * i ;
end
iv = 1:numel(x);
Lv = x <= y;
zm(i1,:) = [x y];
plot3(iv, x, ones(size(iv))*multiplier(i1))
% hold on
plot3(iv, y, ones(size(iv))*multiplier(i1))
% figure(1)
patch([iv(Lv) flip(iv(Lv))], [x(Lv) flip(y(Lv))], [ones(size(x(Lv)))*multiplier(1) ones(size(flip(y(Lv))))*multiplier(i1)], 'g', 'EdgeColor','none')
view(-30,30)
end
hold off
grid on
This is difficult to do with a patch plot. A surf plot wopuld be easier. The problem is that the numbers of elements in both plots would have to be the same, and this would likely require using interp1 to make their sizes equal.
.

댓글 수: 2

Aditya Zade
Aditya Zade 2023년 9월 28일
Its not necessary to use patch. You can let me know what would be a better option.
I suggested surf.
For example, since you are interested in a half-cone with unequal ends —
x = [1;1].*linspace(0, 1, 25);
y = [1.5;1;1.5;1].*[sin(pi*x); cos(pi*x)];
z = [2;1].*ones(size(x));
cm = turbo(2);
figure
surf(y([1 2],:), y([3 4],:), z, 'FaceColor','interp', 'EdgeColor','interp')
hold on
surf(y([1 2],[1 end]), y([3 4],[1 end]), z(:,[1 end]), 'FaceColor','interp', 'EdgeColor','interp')
patch(y(1,:), y(3,:), z(1,:), cm(2,:), 'EdgeColor',[1 1 1]*0.25) % Upper Surface
patch(y(2,:), y(4,:), z(2,:), cm(1,:), 'EdgeColor',[1 1 1]*0.25) % Lower Surface
hold off
xlabel('X')
ylabel('Y')
zlabel('Z')
colormap(turbo)
axis('equal')
title('Expanding Closed Half Cone')
Rotate it to see that the upper and lower surfaces are closed with patch plots in the appropriate colours. Change the radial dimensions (the 4-element column vector in ‘y’) to change its shape. The rest of the code should adapt to those changes.
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

질문:

2023년 9월 28일

댓글:

2023년 9월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by