- ‘TR’ (triangulation object) in ‘x’
- file format in ‘y’(binary/text)
- attributes when the file is binary in ‘z’
- solid identification numbers when the file is text in ‘c’.
Opening STL file using stlread function
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi
This is a line from a code to open binary stl files. My understanding was that the x,y,z vertex coordinates and colours would be stored using this
[x,y,z,c] = stlread(Filename.stl);
I tried to rewrite it as
random.stl=stlread('01_random.stl');
x = random.stl.Points(:,1);
y = random.stl.Points(:,2);
z = random.stl.Points(:,3);
The first line returns
- x - xxxx*3 triangulation
- y-binary
- z xxxx*1 uint16
- c xxxx*1 double
but my code returns
- stl xxxx*3 triangulation
- x,y,z all as xxxx*1 double
- the x,y,z coordinates are stored
Can some explain the first line? What was it meant to do because the values of x,y,z and c are not of the same type.
0 comentarios
Respuestas (1)
T.Nikhil kumar
el 20 de Oct. de 2023
Hello Angel,
I understand that you want to know why the outputs of ‘stlread’ function are different from your expectation.
In the first case, the ‘stlread’ function returns:
It follows the below mentioned syntax:
[TR,fileformat,attributes,solidID] = stlread(filename);
In the second case, a struct of the name ‘random’ is created which has ‘stl’ as a field. This ‘stl’ field contains the ‘triangulation’ type object that is read from the input file. This ‘triangulation’ object has a ‘Points’ property and each row of this property represents the coordinates of a vertex.
You can refer to the following documentation to understand more about ‘stlread’ function.
Hope this helps!
1 comentario
DGM
el 14 de Jul. de 2025
Editada: DGM
el 14 de Jul. de 2025
This is correct, but it's worth noting why the confusion occurred. This answer describes how MATLAB's STL decoder behaves, but OP found some random code snippet that was based on an ancient third-party decoder from FEX #6678. There are five or six decoders on the File Exchange that all share the same name as the built-in decoder, and there are tons of examples and answers on the forum that reference them.
As we can see, the tools are not all the same. They have various features and limitations, and output the data in different forms. Either get the tool for which your code is written, or write your code to suit the tools you're using.
FWIW, if the file is a binary STL with color data, it will be returned in the 'attributes' data in raw form. It should be a 16b packed field formatted in blocks of 5b each for the color components and a trailing flag bit. Which colors are which, and what the flag means all depend on what software created the file.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!