stl - error too many output arguments

5 ビュー (過去 30 日間)
Diego Hens
Diego Hens 2020 年 8 月 10 日
回答済み: Diego Hens 2020 年 8 月 14 日
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 :)

採用された回答

Diego Hens
Diego Hens 2020 年 8 月 14 日
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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSTL (STereoLithography) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by