How to update the Struct value in the workspace from the MATLAB GUI app designer?
7 次查看(过去 30 天)
显示 更早的评论
I am designing the GUI using the matlab app builder, I want to change(assign) the values of struct which is already present in the workspace using the GUI , but I have used the assignin function for 'variables' its works well but for the 'struct' I dont know how to change.
I want to change the car.year value from the GUI.
0 个评论
采纳的回答
dpb
2021-8-14
A struct variable is a variable, just as any other...
function testit(s)
v=inputname(1);
s.year=s.year+10;
assignin('base',v,s);
end
Illustration --
>> car=struct('year',2020,'loan',25000,'counts',10)
car =
struct with fields:
year: 2020
loan: 25000
counts: 10
>> testit(car)
>> car
car =
struct with fields:
year: 2030
loan: 25000
counts: 10
>>
3 个评论
dpb
2021-8-15
You adapt the idea of the function to your usage -- if the struct in question is fixed and immutable, then you can simply encode the variable name as text.
If it can be variable, then you'll need to be able to pass the name to the function and keep it as part of the app data structures.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!