How to export 3D data from Matlab as a stl or obj file
81 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I am new in MatLab and use it to create visual graphics for my work and never worked with the generated code or wrote code for matlab till now.
I generated the graphic below, which I need to print with 3D printer. There is no connection to the antennas, I just use the visual form. I need it in .stl or .obj file format so I can import in in the 3D printer program.
I red about stlwrite function in this forum and tried to use it in the generated code of my graphic, but unfortunately it is not possible for me to generate the .stl file on this way.
Could you please help me to have this in .stl format?
Here is the graphic:

this is the generated code of it:
%MATLAB Code from Sensor Array Analyzer App
%Generated by MATLAB 8.4 and Phased Array System Toolbox 2.3
%Generated on 16-May-2016 17:17:33
addpath('E:\_matlab stuff\stlwrite')
% Create a uniform hexagonal array
rows = [1:4 3:-1:1];
Radius = 1*(3);
d = 1;
pos = zeros(3,1);
count = 0;
for idx = 1:length(rows)
y = -Radius/2 -(rows(idx)-1)*d*0.5:d: Radius/2+(rows(idx)-1)*d*0.5;
pos(2, count+1:count+length(y)) = y;
pos(3, count+1:count+length(y)) = sqrt(3)/2*Radius - (idx-1)*d*sind(60);
count = count + length(y);
end
h = phased.ConformalArray('ElementPosition', pos, 'ElementNormal', ...
zeros(2, size(pos, 2)));
h.Element = ...
phased.IsotropicAntennaElement;
%Assign frequencies and propagation speed
F = 300000000;
PS = 300000000;
%Plot the directivity pattern
pr = plotResponse(h, F(1), PS, 'Unit','dbi', 'Format', 'Polar', ...
'RespCut', '3D');
set(pr, 'LineStyle', 'none');
%Adjust the view angles
view(25, 25);
%Get the title
title = get(gca, 'title');
title_str = get(title, 'String');
%Modify the title
[Fval, ~, Fletter] = engunits(F(1));
title_str = [title_str sprintf('\n') ...
num2str(Fval) ' ' Fletter 'Hz No Steering'];
set(title, 'String', title_str);
-----------------
thank you very much in advance
Dimi
1 comentario
Respuestas (2)
Honglei Chen
el 17 de Mayo de 2016
I have never done this so I cannot guarantee the workflow. However, the figure generated by the above code is a surf plot and the following File Exchange submission claims that it can translate surf data to .stl file.
HTH
4 comentarios
Yaroslav Rybka
el 3 de Mzo. de 2019
I know this is an old and probably irrelevant at this point for the OP, but for all those who find this thread in the future:
What you should have in the variable 'h', according to the documentation is the surface handle. If not, the handle could be retrieved with :
h = gco;
This handle can provide access to the coordinates you need, all you have to do is reference the right fields:
X = h.XData;
Y = h.YData;
Z = h.ZData;
It's useful to remember that even with only the plot of the data, you can retrieve or update the said data .
DGM
el 27 de Sept. de 2025 a las 1:49
If you can use surf2stl(), you can just use surf2patch() and use any competent STL encoder to do the job. Things have changed since 2016, but in modern versions, no third party tools are needed.
% Create a uniform hexagonal array
rows = [1:4 3:-1:1];
Radius = 1*(3);
d = 1;
pos = zeros(3,1);
count = 0;
for idx = 1:length(rows)
y = -Radius/2 -(rows(idx)-1)*d*0.5:d: Radius/2+(rows(idx)-1)*d*0.5;
pos(2, count+1:count+length(y)) = y;
pos(3, count+1:count+length(y)) = sqrt(3)/2*Radius - (idx-1)*d*sind(60);
count = count + length(y);
end
h = phased.ConformalArray('ElementPosition', pos, 'ElementNormal', zeros(2, size(pos, 2)));
h.Element = phased.IsotropicAntennaElement;
% Assign frequencies and propagation speed
F = 300000000;
PS = 300000000;
% Plot the directivity pattern
% the title and graphical properties are irrelevant.
hp = plotResponse(h, F(1), PS, 'Unit','dbi', 'Format', 'Polar', 'RespCut', '3D');
% the plot is a surf plot. it's gridded data. triangulate it.
[F V] = surf2patch(hp.XData,hp.YData,hp.ZData,'triangles');
% modern versions since R2018b have a built-in STL encoder.
stlwrite(triangulation(F,V),'test.stl')
% read back the file so that we can prove it worked.
figure
T = stlread('test.stl');
trisurf(T,'facecolor',[1 1 1]*0.8,'edgecolor','none')
view(3); view(-30,47); camlight;
axis equal; grid on
See also:
Young Dae
el 14 de Sept. de 2018
Editada: Young Dae
el 14 de Sept. de 2018
I think this link will help you a lot! https://www.mathworks.com/matlabcentral/fileexchange/68794-make-stl-of-3d-array-optimal-for-3d-printing
1 comentario
DGM
el 27 de Sept. de 2025 a las 1:50
That isn't applicable to gridded surf data or triangulated meshes. That's for volumetric images.
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!