Update a value in a struct in another function
Mostrar comentarios más antiguos
I have a struct which is initialized by this:
function myStruct = defult_config
myStruct.myLenth = 1;
end
myStruct.myLength = 1 is an initial value and it needs to be updated by another fuction, myUpdate:
function out = myUpdate(myStruct)
myStruct.myLength = 2;
out = [];
end
However, myUpdate doesn't update myStruct and myStruct.myLength is still shown 1.
Any way to update a value in a struct by another function?
Respuesta aceptada
Más respuestas (1)
You must return the modified myStruct from myUpdate():
myStruct.myLength = 1
myStruct = myUpdate(myStruct)
function myStruct = myUpdate(myStruct)
myStruct.myLength = 2;
end
Categorías
Más información sobre Structures en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!