Converting matlab file to stl file

13 ビュー (過去 30 日間)
Anh Phan Viet
Anh Phan Viet 2020 年 3 月 16 日
回答済み: DGM 2025 年 7 月 17 日
Hello everyone, Can anyone please help me convert matlab file to file stl. My plot 3D consists of 7 sets of [X,Y,Z]. I've tried function surf2stl, it requires X,Y,Z. Therefore I concatenated 7 [X1 X2 ... X7] = X Y and Z also. But the graph doesnt look like the one I need.

回答 (2 件)

Kevin Chng
Kevin Chng 2020 年 3 月 17 日
  1 件のコメント
Anh Phan Viet
Anh Phan Viet 2020 年 3 月 17 日
編集済み: Anh Phan Viet 2020 年 3 月 17 日
Sorry but I've not succeeded. Maybe the reason is that: I have [X1 Y1 Z1], [X2 Y2 Z2], ..., [X7 Y7 Z7] while this can only accept 1 set [X Y Z]. However, when I combined 7 sets of coordinates to 1 set, I've met some errors with my stl file.

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


DGM
DGM 2025 年 7 月 17 日
For example:
% you have multiple objects defined by gridded xyz data
[x1,y1,z1] = peaks(20);
[x2,y2,z2] = sphere(20);
z2 = z2 + 6;
% plot them if you want
hs(1) = surf(x1,y1,z1); hold on
hs(2) = surf(x2,y2,z2);
axis equal
% convert the gridded data to triangulated F,V data
% surf2patch() can accept surf handles or
% it can also accept the XYZ arrays directly
for k = 1:numel(hs)
% gridded XYZ to F,V lists
[thisF thisV] = surf2patch(hs(k),'triangles');
% concatenate the F,V lists
if k == 1
F = thisF;
V = thisV;
else
F = [F; thisF + size(V,1)]; %#ok<*AGROW>
V = [V; thisV];
end
end
% write the file
T = triangulation(F,V);
stlwrite(T,'test.stl')
% read it back just to show the result
T = stlread('test.stl');
trisurf(T,'facecolor',[1 1 1]*0.8,'edgecolor','none')
view(3); view(-30,33); camlight;
axis equal; grid on

カテゴリ

Help Center および File ExchangeSTL (STereoLithography) についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by