Help with using scanf and editing a txt file?
2 views (last 30 days)
I'm trying to modify an stl file to eventually 3D print. I am trying to take out the bottom half of the object by using matlab. Essentially, I converted the stl file to .txt so I can analyze the z values to cut away the bottom half. I am trying to use the scanf function or something like it to read the vertices of the triangles, find max and min of xyz, and delete triangles if z<(zmax+zmin)/2. How can I accomplish this?
Guillaume on 20 Jul 2018
Edited: Guillaume on 20 Jul 2018
This is how I'd read all the vertices.
% all vertices are made of 3 coordinates
% all faces are made of 3 vertices
%the code completely ignore the non-vertex lines
lines = strsplit(fileread('thinker.txt'), \n'); %read whole file and split into lines
vertlines = strjoin(lines(startsWith(lines, 'vertex')), '\n'); %identify vertex lines and rejoin
vertices = reshape(sscanf(vertlines, 'vertex %f%f%f\n'), 3, 3, ); %read vertices coordinates and reshape into something useful
This will give you a 3 x Nvertex x Nfacet matrix.
As you've not explained what filtering you want to do after that, I can't help you further.