Can a MATLAB function edit the input?

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?

 Respuesta aceptada

Steve Eddins
Steve Eddins el 19 de Ag. de 2021

0 votos

You'll need your class to subclass handle. See the documentation page "Implementing Linked Lists with Classes" for details.

2 comentarios

Lorcan O'Connor
Lorcan O'Connor el 19 de Ag. de 2021
Thanks - in this respect isn't MATLAB much more awkward than other oop languages?
Steve Eddins
Steve Eddins el 19 de Ag. de 2021
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. :-)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2019b

Preguntada:

el 19 de Ag. de 2021

Comentada:

el 19 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by