Borrar filtros
Borrar filtros

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

14 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

dpb
dpb el 14 de Ag. de 2021
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 comentarios
dpb
dpb el 15 de Ag. de 2021
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by