MATLAB: What are the variables for STL file conversion

3dMATLABsurf

What are the X, Y, Z variables to use SURF2STL function? I do not have any of such variables. My goal is to create a stl file so that the model can be 3D printed. I have successfully drawn the model using surf function, but I can’t convert this to STL file.
Original file is a tiff file.
inFile = '/filepath/s04_e037_1arc_v3.tif';
% Creating figure
figure1 = figure
% Reading the tiff file
[Z,R]=geotiffread(inFile);
% Changing Z from int16 to double
Zedited = cast(Z, 'double');
% Limit lat and long for area
LATLIM=[-4.2,-2.8]
LONLIM=[36.8,38.2]
% Construct map axes for region
worldmap(LATLIM, LONLIM)
% Renaming title
title('Figure mountain','FontSize',18);
% Locating the values <= 0 for Zedited
ridzero = find(Zedited<=0);
% Changing the values of 0 to NaN in the vector
Znew=[Zedited];
Znew([ridzero]) = NaN;
% Displaying map data
geoshow(Znew, R, 'DisplayType', 'surface');
% Color the map based on the terrain elevation data, Znew.
% 888 is the number of colours used to colour from min to max elevation.
demcmap(Znew, 888);
% Resizing plot
set(gcf, 'Position', get(0, 'Screensize'));
% I want to create model! Create new figure for surface file
figure2 = figure
% More defined 3D surface to convert to STL/OBJ format for 3D printing!
surf(Znew,'EdgeColor','none','FaceColor','red')
% I do not know the X Y Z variables to convert to STL file type...
% surf2stl('modelsurf.stl',Znew,R,R)

Best Answer

[nx,ny] = size(Znew) ;
[X,Y] = meshgrid(1:ny,1:nx) ;
Z = Znew ;
Now you have X,Y,Z..you can write them into .stl file.