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

조회 수: 21 (최근 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.
Manoj Devaraju
Manoj Devaraju 2021년 8월 16일
Ok Thanks for your suggestions. Its working fine

댓글을 달려면 로그인하십시오.

추가 답변 (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