MATLAB: Multiple 2D in 3D Plot

MATLABMATLAB and Simulink Student Suite

Hi everyone,
I have a problem, how do I get my 2d plot what I created with the code in 3D. I would be happy if you could help me.
%Initalisieurung der globalen Variablen
global C_Dim C Bauteil L R1 R2 D
%Achsen für Berechnung
%2 Y Achsen für Innen und Außenradius
x= zeros(C_Dim(1,1)*4);
y= zeros(C_Dim(1,1)*4);
y2= zeros(C_Dim(1,1)*4);
%Variable für Startwert Dekleration mit Schleife für Durchgang aller
%Variablen
g = 1;
startwert = 0;
for i = 1: C_Dim(1,1)
Bauteil = char(C(i,1));
L = str2double(C(i,2));
R1 = str2double(C(i,3));
R2 = str2double(C(i,4));
x(g,1)= startwert;
x(g+1,1)=startwert+L;
%Fallunterscheidung der einzelnen Bauteile
switch Bauteil
case 'Z'
R1=R2;
%y-wert Außenradius
y(g,1)=R2;
y(g+1,1)=R2;
g=g+2;
startwert=startwert+L;
%Spiegelung der Figur


if i==C_Dim(1,1)
v=0;
for u=(i-1)*2:-1:1
v=v+1;
x((i-1)*2+v,1) = x(u,1);
y((i-1)*2+v,1) = -y(u,1);
y2((i-1)*2+v,1)= -y2(u,1);
end
x(end,1)=x(1,1);
y(end,1)=y(1,1);
y2(end,1)= y2(1,1);
end
%Case Z Ende

case 'K' %Abfrage Konus
y(g,1)=R1;
y(g+1,1)=R2;
g=g+2;
startwert=startwert+L;
%Spiegelung der Figur
if i==C_Dim(1,1)
v=0;
for u=(i-1)*2:-1:1
v=v+1;
x((i-1)*2+v,1) = x(u,1);
y((i-1)*2+v,1) = -y(u,1);
y2((i-1)*2+v,1)= -y2(u,1);
end
x(end,1)=x(1,1);
y(end,1)=y(1,1);
y2(end,1)= y2(1,1);
end
% Case K Ende
case 'HZ' %Abfrage Zylinder
y(g,1)=R2;
y(g+1,1)=R2;
y2(g,1)=R1;
y2(g+1,1)=R1;
g=g+2;
startwert=startwert+L;
%Spiegelung der Figur
if i==C_Dim(1,1)
v=0;
for u=(i-1)*2:-1:1
v=v+1;
x((i-1)*2+v,1) = x(u,1);
y((i-1)*2+v,1) = -y(u,1);
y2((i-1)*2+v,1)= -y2(u,1);
end
x(end,1)=x(1,1);
y(end,1)=y(1,1);
y2(end,1)= y2(1,1);
end
%Case Z Ende
end
%Ende Switch
%Bestimmung der Skalierung für die x-Achse bzw y-Achse
max_R1=max(str2double(C(:,3)));
max_R2=max(str2double(C(:,4)));
R_max=max(max_R1,max_R2);
%Skalierung y-Achse
y_max=(R_max)+100;
%Skalierung x-Achse
x_max=startwert+100;
end
%Plot
plot(x,y,'blue-',x,y2,'green--')
ylim([-y_max y_max]);
xlim([0 x_max])
Title=title('2D Darstellung des Rotorstrangs');
xlabel('Länge [mm]')
ylabel('Radius [mm]')

Best Answer

If i understood you correctly: you have profile (some curve) and you want to rotate it to obtain 3D figure
Here is an example
clc,clear
% some data
data = [ 0.0749 0.5424
0.2339 0.5453
0.3906 0.7295
0.4090 0.5278
0.5495 0.5307
0.5495 0.6447
0.6970 0.6447
0.7039 0.5307
0.8145 0.5307];
t = linspace(0+0.1,pi,20);
z = data(:,1);
r = data(:,2);
[T,Z] = meshgrid(t,z); % mesh for angle and Z
[~,R] = meshgrid(t,r); % mesh for radius
[X,Y] = pol2cart(T,R); % convert to cartesian
plot3(z,r*0,r,'linewidth',2) % plot profile
hold on
surf(Z,Y,X,'Facecolor','y','Edgecolor','none')
hold off
camlight('headlight');
material('dull');
view(3)
axis equal