Can a MATLAB function edit the input?

3 次查看(过去 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?

采纳的回答

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 个评论
Lorcan O'Connor
Lorcan O'Connor 2021-8-19
Thanks - in this respect isn't MATLAB much more awkward than other oop languages?
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 个)

类别

Help CenterFile Exchange 中查找有关 Call Python from MATLAB 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by