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!