How to stack-up multiple cases in z axis?

9 vues (au cours des 30 derniers jours)
Aditya Zade
Aditya Zade le 28 Sep 2023
Commenté : Star Strider le 28 Sep 2023
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 commentaires
Aditya Zade
Aditya Zade le 28 Sep 2023
Modifié(e) : Aditya Zade le 28 Sep 2023
The shaded area may look something like this. The semicircular area would get narrower as multiplier becomes low.
Aditya Zade
Aditya Zade le 28 Sep 2023
I have plotted for two cases when multiplier = 40 and 50, but have done in only xy axes.

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 28 Sep 2023
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 commentaires
Aditya Zade
Aditya Zade le 28 Sep 2023
Its not necessary to use patch. You can let me know what would be a better option.
Star Strider
Star Strider le 28 Sep 2023
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.
.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by