Pass String as Variable Into Function
Mostrar comentarios más antiguos
Sorry, I posted a previous question that was convoluted and didn't really address my main concern. I'm trying to pass a string which is the variable name of a pre-existing UI object into the 'set' function inside a callback function. For example, set(variable1, ...), but I'm not sure how to convert the string 'variable1' into the literal word variable1 to be used in 'set'. Any help is appreciated! Thanks.
Edit: I'm not fond of using it, but I tried the eval function:
eval(['set(variable' num2str(1) ', "String", "hello")']) ;
Yet it doesn't work (I get the error "Invalid parameter/value pair arguments.")
Second Edit: I found the solution! Just use handles format instead:
eval(['variable' num2str(1) '.String = "hello"'])
1 comentario
Mike Wilson
el 21 de Sept. de 2020
Why bother giving such feedback when obviously you feel so much superior to those who know less than you. Get off your high horse and be nice to people.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Interactive Control and Callbacks en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!