How can I get the selected date from "uicalendar" as a variable in workspace using Financial Toolbox?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 8 Nov 2011
Modificato: MathWorks Support Team
il 14 Ott 2014
I would like to get the selected date from "uicalendar" as a string variable the current workspace.
Risposta accettata
MathWorks Support Team
il 18 Ott 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Dates and Time in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!