stl - error too many output arguments

4 visualizaciones (últimos 30 días)
Diego Hens
Diego Hens el 10 de Ag. de 2020
Editada: DGM el 27 de Sept. de 2025 a las 5:12
Hello,
I have a problem regarding the function stlwrite.
I want to move a stl. file so that the center of mass is at the center of the coordinates system.
A stl object has F, V and N values for the Faces, Vertices and Normal Vectors. F is just the number of the order of the vertices (the first line of the matrix are the numbers 1, 2 and 3), V are the points themselves (there are of course three time more V values than F, because each point has three coordinates X, Y and Z and every face has three points/vertices). This means, if I substract the same number to every point in V, then I'll be moving the object without changing any of the faces or vertices, just the location of the whole.
For this I calculate the center of mass which is the mean of every value of every axis and substract this numbers to the coordinates of V.
% Read the stl file and its values
File1 = stlread('file.stl');
[F, V, N] = stlread('file.stl);
%Calculate the cente of mass by getting the mean of V
CenterofMass =mean(V);
%New value of V (V2);
V2 = V-CencerOfMass;
%Proceed as in stlwrite library and make the triangulation with faces F and vertices V2
TR = triangulation(F, V2);
File2 = stlwrite(TR, 'file2.stl');
Why do I get the following errors?
Error using stlwrite
toot many arguments
Error in File_name (line 76)
File2=stlwrite(TR, 'file2.stl');
Thank you :)

Respuesta aceptada

Diego Hens
Diego Hens el 14 de Ag. de 2020
I found the solution thanks to a reddit user.
File2 = stlwrite(TR, 'file2.stl');
This line is wrong. Even if the library says the order is fine, it is not. It should be:
File2 = stlwrite('file2.stl', TR);
Now, to prove it yo can do the following:
[F, V, N] = stlread('FileBefore.stl'); % Notice that this line had a variable name File1 previously.
% That was wrong. stlread is a command like plot() and you can use
% it alone or with [F, V, N] to get those values.
stlwrite('FileAfter.stl',F,V); % You can just write the same file under another name to see that
% it works. If you gave stlread a variable name (File2 for example)
% you can use it here too.
% Now if you change V by multiplying it by 2, it should work just fine
  1 comentario
DGM
DGM el 27 de Sept. de 2025 a las 5:06
Editada: DGM el 27 de Sept. de 2025 a las 5:12
There are a bunch of different and mutually incompatible files that are all called the same thing.
This usage is consistent with stlwrite() which is the built-in STL encoder introduced in R2018b. This only works if TR is a triangulation object.
File2 = stlwrite(TR, 'file2.stl');
This usage is consistent with FEX #20922, where TR is an FV struct, not a triangulation object. It has some extended functionality which may be useful even in modern versions, but it's largely not needed.
File2 = stlwrite('file2.stl', TR);
This is consistent with FEX #22409, which is an old, incomplete decoder which nobody should be using in any modern version.
[F, V, N] = stlread('FileBefore.stl');
If you are running R2018b and have a bunch of old FEX downloads that are shadowing built-in tools, either delete them or rename them so that they don't cause conflicts. Keep this naming ambiguity in mind, since the forum is filled with undisclosed references to FEX tools with the same names.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by