i had constructed a code to plot 3d graph Magnetic Field
theta = [0:0.101:pi/2,3*pi/2:0.01:2*pi];
rho = sqrt(cos(theta));
[x,y]=pol2cart(theta,rho);
x1=real(x);
y1=real(y);
x2=[x1,-x1];
y2=[y1,-y1];
z=zeros(1,632);
plot3(x2,y2,z); hold on
for th=(29:29:340)
rotate(plot3(x2,y2,z,'b'),[0 1 0],th);
end
rho = 2*sqrt(cos(theta));
[x,y]= plo2cart(theta, rho);
x1=real(x);
y1=real(y);
x2=[x1,-x1];
y2=[y1,-y1];
for the=(20:20:340)
rotate(plot3(x2,y2,z,'a'),[0 1 0],th);
end
The problem is im getting error - "Vectors must be the same length.".any ideas?

 採用された回答

Star Strider
Star Strider 2021 年 1 月 9 日

0 投票

See if this does what you want:
theta = [0:0.101:pi/2,3*pi/2:0.01:2*pi];
rho = sqrt(cos(theta));
[x,y]=pol2cart(theta,rho);
x1=real(x);
y1=real(y);
x2=[x1,-x1];
y2=[y1,-y1];
z=zeros(size(x2));
figure
plot3(x2,y2,z)
hold on
for th=(29:29:340)
p1 = plot3(x2,y2,z,'b');
rotate(p1,[0 1 0],th)
end
rho = 2*sqrt(cos(theta));
[x,y]= pol2cart(theta, rho);
x1=real(x);
y1=real(y);
x2=[x1,-x1];
y2=[y1,-y1];
for the=(20:20:340)
p2 = plot3(x2,y2,z,'r');
rotate(p2,[0 1 0],th)
end
hold off
grid on
legend([p1,p2],'b','a')
A few changes were necessary to make it work correctly.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Particle & Nuclear Physics についてさらに検索

製品

リリース

R2018b

質問済み:

2021 年 1 月 9 日

回答済み:

2021 年 1 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by