How can I get the selected date from "uicalendar" as a variable in workspace using Financial Toolbox?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 8 de Nov. de 2011
Editada: MathWorks Support Team
el 14 de Oct. de 2014
I would like to get the selected date from "uicalendar" as a string variable the current workspace.
Respuesta aceptada
MathWorks Support Team
el 18 de Oct. de 2013
There are no means by which you can directly save the selected date in the "uicalendar" to a variable in MATLAB workspace. The date selected must be exported to a property of a graphical object (for example, the "String" property of a "uicontrol"). Once this happens, the value of the property can be extracted to a variable in the workspace.
Following is an example code which would help you copy the selected date form the "uicalendar" to a variable in MATLAB workspace.
1. Create a figure and invoke "uicalendar" by run the following code:
h = uicontrol('Style', 'pushbutton', 'Position', [20 150 100 70]);
uicalendar('DestinationUI', {h, 'String'});
2. Once the "uicalendar" is invoked select a suitable date from the same and press "OK". Execute the following "get" function to capture the date as a string variable.
val1 = get(h,'String');
However, please note that using "get" before selecting a date in the "uicalendar" will return the previous value of the string inside the handle, "h". Hence, to apply this workaround, it needs to be ensured that the "get" command is used only after the data is selected.
If this is being done inside a script or a function, you can use "<http://www.mathworks.com/help/matlab/ref/waitfor.html waitfor>" to halt execution until the date is selected. The following statements illustrate this:
h = uicontrol('Style', 'pushbutton', 'Position', [20 150 100 70]);
uicalendar('DestinationUI', {h, 'String'});
% Now wait for the string to be updated
waitfor(h,'String');
val1 = get(h,'String');
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Dates and Time 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!