Changing Structure field value from a function
10 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2016-11-9
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.
更多回答(1 个)
Guillaume
2016-11-9
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Other Formats 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!