How to obtain information from handle structure?

3 visualizaciones (últimos 30 días)
Valeriy
Valeriy el 20 de En. de 2018
Comentada: Walter Roberson el 21 de En. de 2018
Hi everybody, I have following situation
function outParameters = Main(inParameters)
...
Doing something
...
h = figure(KeyPressFCN,@WhatPressed);
plot(WhatNecessary);
...
function WhatPressed(src, evnt)
switch evnt.Key
case 'a'
...
ProcessedData
case 'b'
...
end
end % of WhatPressed
outParameters = workWith(ProcessedData);
end % of Main
In above version I calculated ProcessedData, but can't pass it into Main program.
What is the simplest way to pass result of calculations from WhatPressed function into Main one?
I know the way how to do this, using GUI with main window and processing of its handle structure and I use it for control of many operations, but in this case I need only to pass a few parameters from WhatPressed function into Main one?
Thanks for constructive ideas

Respuesta aceptada

Walter Roberson
Walter Roberson el 20 de En. de 2018
  7 comentarios
Valeriy
Valeriy el 20 de En. de 2018
Excellent, you have moved me further in understanding all of this staff.
Should I use uiresume(newfig) during the exit part of WhatPressed?
Appreciate your efficient help
Walter Roberson
Walter Roberson el 20 de En. de 2018
If WhatPressed is being closed then you do not need uiresume() as uiwait() will detect that the figure closed. uiwait() / uiresume() could be used in a loop in the main function for the GUI to communicate some information back to the main routine without exiting -- uiresume() can be used to signal "There is data ready for you" without needing to close the figure doing the data collection. But if you are closing the figure anyhow then you do not need to bother to uiresume()
If you have a figure used for data interaction that is going to be used multiple times and should not be available in-between, then instead of creating the interaction figure each time, you can arrange to have it uiresume() and then set itself invisible; when you need it again, set its visibility on and uiwait() on it.

Iniciar sesión para comentar.

Más respuestas (1)

Valeriy
Valeriy el 21 de En. de 2018
Dear Walter
I have realized workflow you have proposed, it works excellent. I have to tell you that this was not the first time I try to solve such task. I carefully searched help, forums, other publications. I found how to pass additional parameters into space of figure, but your post is first realization of inverse transfer of information. I'm sure that this solution is useful not only for me, but for many peoples who have similar tasks. By this reason in could be presented into regular matlab help.
By the way, for the case of appdata and earlier Matlab versions, should I replace all occurences of curfig by 0?
Thanks again for your efficient help
  1 comentario
Walter Roberson
Walter Roberson el 21 de En. de 2018
Easier to assign 0 to curfig to isolate the effects. Or use a more meaningful variable name.

Iniciar sesión para comentar.

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by