function use in GUI returned values

조회 수: 1 (최근 30일)
aya
aya 2014년 7월 12일
편집: Ben11 2014년 7월 12일
I have several push buttons and text box in my GUI that I mange how to get the chosen or written value, as showen in the code below for example
itemsx = get(hObject,'String');
index_selectedx = get(hObject,'Value');
Dx = itemsx{index_selectedx};
now I have new button called run this button call a function called start_simulation() what I need to do is how to return the value of Dx as an input to start_simulation() function the known way which is start_simulation(Dx) doesn't work
  댓글 수: 1
Image Analyst
Image Analyst 2014년 7월 12일
What callback it that code in? One of the buttons or the textbox???

댓글을 달려면 로그인하십시오.

답변 (1개)

Ben11
Ben11 2014년 7월 12일
You might need to use
Dx = str2num(Dx)
before calling the function is it possible?
  댓글 수: 2
aya
aya 2014년 7월 12일
doesn't work, it seems that i only can use the value of Dx in the callback function of the drop down menu that i take it from the value is not readable by other push buttons
Ben11
Ben11 2014년 7월 12일
편집: Ben11 2014년 7월 12일
Well the use of hObject is for a particular callback, i.e. the one currently executing. If you want to access the content of other elements (pushbuttons, popup menus, etc) you need to use their handles.
In your example, when pressing the pushbutton you want to call:
itemsx = get(handles.textbox1,'String');
index_selectedx = get(handles.textbox1,'Value');
Dx = itemsx{index_selectedx};
which is more likely to work. In my example "handles.textbox1" is the handles generated by GUIDE (assuming you used GUIDE) that you can change to anything you want. It it does not work please show the error message so we can help you better.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by