Changing Structure field value from a function
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MoHAJNEN komo olkm
el 9 de Nov. de 2016
Comentada: Walter Roberson
el 9 de Nov. de 2016
Greetings all,
I have a question regarding the Structure field value. I'm trying to change a field of my structure that is already in the workspace. as follows: mys(1).id = {100};
I can do that from the command line and the value changes, but that is not happening from inside the function. Any idea why is that ?
2 comentarios
KSSV
el 9 de Nov. de 2016
Are you sending the data which in work-space to the function? Show us your code.
Respuesta aceptada
Walter Roberson
el 9 de Nov. de 2016
You need to have the entire variable as output from your function. Or if the function returns just the new value then the caller needs to assign it to the field by name.
3 comentarios
Walter Roberson
el 9 de Nov. de 2016
function s=test(s)
s.something = newvalue;
Called with
A = test(A)
Más respuestas (1)
Guillaume
el 9 de Nov. de 2016
Matlab is pass-by-value. functions always receive the copy of the variable. Any change you make to variables are only local to the function unless the function also returns the variable as an output and the caller assigns that output back to the original variable.
0 comentarios
Ver también
Categorías
Más información sobre Other Formats en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!