Create mfile for a loop function
조회 수: 1 (최근 30일)
이전 댓글 표시
I was wondering if it is possible to create a function in mfile format for the bellow code (b0_T03_s is a table):
% to find x velocity and x position for bike #0
for i= 0:1:23;
b0_T03_s(2+i,25) = b0_T03_s(1+i,25) + b0_T03_s(1+i,23);
b0_T03_s(2+i,24) = b0_T03_s(1+i,24) + b0_T03_s(1+i,25) + (0.5*b0_T03_s(1+i,23));
end
댓글 수: 2
답변 (1개)
Cris LaPierre
2022년 7월 21일
Yes, it's possible. See this page on creating live functions in a live script using the Refactor tool.
The orginal and refactored code must be live scripts (.mlx file type) to use this tool, but once created, you can save as *.m if necessary.
댓글 수: 6
Cris LaPierre
2022년 7월 22일
I suggest taking a look at this page: https://www.mathworks.com/help/matlab/matlab_prog/create-functions-in-files.html
You will need to keep in mind varible scope. Function only have access to the variables passed in as inputs or that are created inside the function.
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!