Update a value in a struct in another function
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (1)
You must return the modified myStruct from myUpdate():
myStruct.myLength = 1
myStruct = myUpdate(myStruct)
function myStruct = myUpdate(myStruct)
myStruct.myLength = 2;
end
Catégories
En savoir plus sur Structures dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!