Can a MATLAB function edit the input?
조회 수: 2 (최근 30일)
이전 댓글 표시
In Python, I could define, say, a linked list via the class 'node' with attribute 'next', then define a recursive function
def addtoend(root, newnode):
if root.next == None:
root.next = newnode
else: addtoend(root.next,newnode)
I can't figure out how do implement this in MATLAB - I can define the class 'node' but MATLAB doesn't seem to allow functions to modify the input and keep it in the workspace. Is there any way around this?
댓글 수: 0
채택된 답변
Steve Eddins
2021년 8월 19일
You'll need your class to subclass handle. See the documentation page "Implementing Linked Lists with Classes" for details.
댓글 수: 2
Steve Eddins
2021년 8월 19일
There are many benefits to the normal MATLAB function-calling behavior in which functions do not modify their inputs. I'll leave it up to you to assess the balance of pros and cons for your own work. :-)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!