Converting matlab file to stl file

조회 수: 12 (최근 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 CenterFile Exchange에서 STL (STereoLithography)에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by