How can I get the selected date from "uicalendar" as a variable in workspace using Financial Toolbox?
1 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2011-11-8
编辑: MathWorks Support Team
2014-10-14
I would like to get the selected date from "uicalendar" as a string variable the current workspace.
采纳的回答
MathWorks Support Team
2013-10-18
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!