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!