How to update the Struct value in the workspace from the MATLAB GUI app designer?

23 次查看(过去 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.

采纳的回答

dpb
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
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 CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by