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]')

6 个评论

Where is the data? Can't run without variables C and C_Dim
Can I send you my entire script with my test data. I got a 3d plot. Unfortunately it does not represent correctly. You would help me very much. Can I send this to you by email? I really need it. No one has been able to help me until now.
Please post it here
Use attachments button if it's large
I used Gui, there are 5 related scripts. Should I post all the scripts with my test data?
Maybe you can show the picture you have and the result you want to achieve
I don't think to attach 5 script is good idea

请先登录,再进行评论。

 采纳的回答

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

3 个评论

Thanks for your code.
If I e.g. a cylinder with length 5 and radius 6 is shown incorrectly.
I just my code at the end of yours
z = x;
r = y;
t = linspace(0,pi,50);
[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
figure
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
img1.png
please accept the answer

请先登录,再进行评论。

更多回答(2 个)

Mustafa Ucar
Mustafa Ucar 2020-2-12

0 个投票

my data looks like this. The first column lists components. Namely cylinders, hollow cylinders and cones. The second column lists the length, the third column the inner radius. Fourth column outer radius. The other dates are not important.
Bautyp L[mm] R1[mm] R2[mm] Rho G-Modul[N/mm≤]
Z 100 0 350 8 80000
K 150 250 150 8 81000
Z 54 0 150 8 81000
K 200 250 350 8 79000
Z 300 0 300 8 81000
K 200 500 100 8 81000
Z 300 0 65 8 80000
K 100 20 350 8 80000
K 300 20 85 8 79000
Z 300 0 65 8 79000
Mustafa Ucar
Mustafa Ucar 2020-2-12

0 个投票

Thanksssss, it works. I am sooo happy. Thank you very much!!!!

类别

帮助中心File Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by