简体   繁体   English

使用向量在Matlab中绘制多于一条曲线的3D模型

[英]Draw 3D model of more than one curve in matlab with vectors

I'm doing a project that involves making a 3D model of the cornea in matlab. 我正在做一个涉及在Matlab中制作角膜3D模型的项目。 I have 6 plot3 in the same graph to draw one cornea 我在同一张图中有6个plot3画了一个角膜

在此处输入图片说明

but now i want a surface plot. 但是现在我想要一个表面图。

在此处输入图片说明

Don't mind the curve orientation. 不要介意曲线方向。 Note that all the plot3 have x, y and z that are vectors 注意,所有plot3的向量均为x,y和z

Thanks in advance 提前致谢

If I were you I would use the Surf command doku surf . 如果我是你,我将使用Surf命令doku surf It is used to display [x,y,z] data. 用于显示[x,y,z]数据。 Since you have not have as many touples of data (just 6) you will have to interpolate all the other values. 由于您没有太多的数据(只有6个),因此您必须对所有其他值进行插值。 Therefore I would use the scattered interpolant function doku scattered interpolant . 因此,我将使用分散插值函数doku分散插值

!!!!!!!!!!!!!!Take care all this is pseudocode!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!请注意,所有这些都是伪代码!

F = scatteredInterpolant(x_existing,y_existing,z_existing);

generates a scattered interpolant object. 生成一个分散的插值对象。 You do already feed your already existing data in there. 您确实已经在其中输入了现有数据。 Afterwards you generate the points at which you want to interpolate: 然后,生成要进行插值的点:

%generates samples from -4 t0 4 in 0.05 steps
   [x_sample,y_sample] = meshgrid(-4:0.05:4,-4:0.05:4);

Now you calculate the fitted z values using the scattered interpolant obj 现在,您使用分散的内插obj计算拟合的z值

z_interpolated=F(x_sample,y_sample) %interpolates
surf(x_sample,y_sample,z_interpolated) %plots with surf between -4 and 4

!!!!!!!!!!!!!!!From here working code!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!从这里开始工作代码!!!!!!!!!!!!!!!!!!!!!

   %serialiasation of data (special for this usecase)
x_data=[h0(30:632,6);(a30(28:408,3))+0.527;(a60(276:632,3));(a90(26:575,3))+3.417;(a120(188:586,3))-0.6625;(a150(16:380,3))+1.173];
y_data=[(h0(30:632,5));((a30(28:408,2))-0.9128);(a60(276:632,2));(a90(26:575,2));(a120(188:586,2))-0.3825;((a150(16:380,2))+2.032)];
z_data=[yA0;yA30+0.162;yA60;yA90+0.837;yA120+0.135;yA150+0.135];

% cleaning the data of nan values
x_data=x_data(~isnan(z_data));
y_data=y_data(~isnan(z_data));
z_data=z_data(~isnan(z_data));%random for the looks


%interpolating
F=scatteredInterpolant(x_data,y_data,z_data);
%read yourself what this does
F.Method = 'natural';
F.ExtrapolationMethod = 'none';

%choosing sample points
[x_sample,y_sample] = meshgrid(-6:0.05:6,-6:0.05:6);

%interpolation
z_interpolated=F(x_sample,y_sample);
%plot
surf(x_sample,y_sample,z_interpolated)

I hope I was able to help you. 希望我能为您提供帮助。 If you try it and it works it would be very nice of you to post the working code here so that in the future here stands a working solution. 如果您尝试并成功,那么将您的有效代码发布到此处,以便将来在这里提供一个有效的解决方案,将是非常不错的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM