how to transfer code in gui?

조회 수: 15 (최근 30일)
cemsi888
cemsi888 2015년 2월 9일
댓글: Adam 2015년 2월 10일
hi i wrote a gui program to first read files than make calculations and plot diagrams etc... In Addition on my gui window i created open button to get file from different pfad.
% The OPEN button
btnNumber=6;
labelStr='OPEN';
callbackStr='turbcomp2(''a=6'')';
%Generic Button Information
btnPos=[left/8 yPos-btnHt*10-0.152-btnHt btnWid btnHt];
uicontrol( 'Style','pushbutton',...
'Units','normalized',...
'Position',btnPos,...
'String','OPEN',...
'Callback',callbackStr);
as a callback function i wrote Programm too it Looks subsequent:
[filename,pathname,filterindex]=uigetfile({'*.*','Allfiles(*.*)'},...
'Pick a file',...
'Multiselect','on');
but i dont know how can i Combine These two codes and how can i write second code which is callback as a function? i am new with gui and i could not find any solution. eventhough i did not understand[hObject, eventdata, handles] i searched in Internet however i could not find sufficient Information. Thnaks
  댓글 수: 4
cemsi888
cemsi888 2015년 2월 10일
I changed something but i got error massage.
'Function definitions are not permitted in this context.'
btnNumber=6;
labelStr='OPEN';
%Generic Button Information
btnPos=[left/8 yPos-btnHt*10-0.152-btnHt btnWid btnHt];
uicontrol( 'Style','pushbutton',...
'Units','normalized',...
'Position',btnPos,...
'String','OPEN',...
'Callback',@callbackStr6fn);
function callbackStr6fn(uicontrol,eventdata)
[filename,pathname,filterindex]=uigetfile({'*.*','Allfiles(*.*)'},...
'Pick a file',...
'Multiselect','on')
end
Adam
Adam 2015년 2월 10일
If you are working in a script you cannot use functions.
GUIDE is the easiest way to create a simple GUI rather than manually creating the UI components. It will also create callbacks for you so you don't need to worry about getting the syntax right.
If you want to create the components yourself then just change your code from a script to a function by adding:
function myFunctionName
at the top of the file and
end
at the end of your main function. Then you can define further sub-function as you appear to be doing there for callbacks.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by