How can I get the selected date from "uicalendar" as a variable in workspace using Financial Toolbox?

1 Ansicht (letzte 30 Tage)

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 18 Okt. 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');

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Produkte


Version

R2009b

Community Treasure Hunt

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

Start Hunting!

Translated by