Update a value in a struct in another function
显示 更早的评论
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?
采纳的回答
更多回答(1 个)
You must return the modified myStruct from myUpdate():
myStruct.myLength = 1
myStruct = myUpdate(myStruct)
function myStruct = myUpdate(myStruct)
myStruct.myLength = 2;
end
类别
在 帮助中心 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!