How to export 3D data from Matlab as a stl or obj file

278 views (last 30 days)
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

Answers (3)

Honglei Chen
Honglei Chen on 17 May 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
  3 Comments
Walter Roberson
Walter Roberson on 15 Jul 2016
You need to click on the Download button of the above link and save the .zip into a convenient directory that is not under your MATLAB installation directory. Unzip it and that will create a new directory. Now use the MATLAB pathtool command to add that directory to your MATLAB path and save the path; you will then be able to use the function.
Yaroslav Rybka
Yaroslav Rybka on 3 Mar 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 .

Sign in to comment.


A D
A D on 27 Oct 2016
Hello Dimi, I also am struggling with these error messages. Did you succeed in exporting the .fig to .stl or .obj? If so, would you be willing to share your process? Thank you for your time.

Young Dae
Young Dae on 14 Sep 2018
Edited: Young Dae on 14 Sep 2018

Community Treasure Hunt

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

Start Hunting!