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 件のコメント

darova
darova 2020 年 2 月 12 日
Where is the data? Can't run without variables C and C_Dim
Mustafa Ucar
Mustafa Ucar 2020 年 2 月 12 日
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.
darova
darova 2020 年 2 月 12 日
Please post it here
darova
darova 2020 年 2 月 12 日
Use attachments button if it's large
Mustafa Ucar
Mustafa Ucar 2020 年 2 月 12 日
I used Gui, there are 5 related scripts. Should I post all the scripts with my test data?
darova
darova 2020 年 2 月 12 日
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

サインインしてコメントする。

 採用された回答

darova
darova 2020 年 2 月 12 日

0 投票

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 件のコメント

Mustafa Ucar
Mustafa Ucar 2020 年 2 月 12 日
Thanks for your code.
If I e.g. a cylinder with length 5 and radius 6 is shown incorrectly.
darova
darova 2020 年 2 月 12 日
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
darova
darova 2020 年 2 月 12 日
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

1 件のコメント

darova
darova 2020 年 2 月 12 日
What do you want me to do with this?

サインインしてコメントする。

Mustafa Ucar
Mustafa Ucar 2020 年 2 月 12 日

0 投票

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

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

タグ

質問済み:

2020 年 2 月 12 日

コメント済み:

2020 年 2 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by