Reading existing function in MATLAB?

조회 수: 1 (최근 30일)
Saurav
Saurav 2024년 4월 23일
편집: DGM 2025년 7월 25일
I have download some function of Matlab for my project work. Now when I am running that function then it is showing error
Error: >> stlRead
Execution of script stlRead as a function is not supported:
I:\Python coding\3d\New findings\vsangelidakis\vsangelidakis-SHAPE-f97791a\lib\stlTools\stlRead.m
Error in stlRead (line 1)
[v, f, n, name] = stlRead('aggregate_1.stl');
I am attcahing the folder of the function.
  댓글 수: 1
DGM
DGM 2025년 7월 25일
편집: DGM 2025년 7월 25일
The attached file is an incomplete, renamed copy of stlGetFormat() from FEX #51200 (stlTools). It's no longer valid code since it's truncated mid-scope, and it was renamed to something that's not even relevant anymore. Despite this file not being usable without error, it's never being used.
These are functions, not scripts. The files stlRead(), stlReadBinary(), stlReadAscii(), stlSlimVerts(), and stlGetFormat() need to be able to call each other as functions. If you remove the function definition, they don't work anymore.
Don't make random edits to a function and try to run it like a script. Make sure the relevant files are on the path, then call it with the appropriate input and output arguments as described in the synopsis.
% this will call stlGetFormat(). depending on the result,
% it will call either stlReadBinary() or stlReadAscii(),
% which will call stlSlimVerts() when it's done.
[V,F] = stlRead('myfile.stl'); % from FEX #51200
In R2018b or newer, you don't need to use stlTools. As Cris mentioned below, you can use stlread and stlwrite instead.

댓글을 달려면 로그인하십시오.

채택된 답변

Cris LaPierre
Cris LaPierre 2024년 4월 23일
편집: Cris LaPierre 2024년 4월 23일
The issue is that your function name is strReads, not stlRead. However, it is best practice to use the same name for the function and the file. You function is actually called stlGetFormat. You should rename your file so that it has the same name as your function, and use that name to call it.
type stlReads.m
function format = stlGetFormat(fileName) %STLGETFORMAT identifies the format of the STL file and returns 'binary' or %'ascii' fid = fopen(fileName); % Check the file size first, since binary files MUST have a size of 84+(50*n) fseek(fid,0,1); % Go to the end of the file fidSIZE = ftell(fid); % Check the size of the file if rem(fidSIZE-84,50) > 0 format = 'ascii';
You can learn more about creating functions in MATLAB here: https://www.mathworks.com/help/matlab/matlab_prog/create-functions-in-files.html
  댓글 수: 1
Cris LaPierre
Cris LaPierre 2024년 4월 23일
Incidentally, MATLAB has an stlread function.
unzip('aggregate_1.zip')
TR = stlread('aggregate_1.stl')
TR =
triangulation with properties: Points: [13535x3 double] ConnectivityList: [27066x3 double]
trimesh(TR)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Downloads에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by