Can a MATLAB function edit the input?

2 ビュー (過去 30 日間)
Lorcan O'Connor
Lorcan O'Connor 2021 年 8 月 19 日
コメント済み: Steve Eddins 2021 年 8 月 19 日
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 == None: = newnode
else: addtoend(,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?


Steve Eddins
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
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 件)




Community Treasure Hunt

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

Start Hunting!

Translated by