GUI 재사용 기능 블록이 계산 정적 텍스트 상자 (s1
, s2
, s3
및 s4
)에 표시되어야하는 값.MATLAB이 I이 값에 두 가능한 텍스트 박스 두 가능한 텍스트 박스의 4 개 개의 스태틱 텍스트 박스 사용자 입력 값 (<code>e1</code> 및 <code>e2</code>)과 가이드에 매트랩 GUI를 만든 기반 한
이 e1
변경 값은 다음과 같이 될 때 값을 계산하고 e1
e2
코드의 각 값에 변화를한다.
% --- Executes on key press with focus on e1 and none of its controls.
function e1_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to e1 (see GCBO)
% eventdata structure with the following fields (see UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
% Start of BLOCK
% Get values from e1 and e2 and calculate other values
handles.levels = str2num(get(handles.e1, 'String'));
handles.edgelength = str2num(get(handles.e2, 'String'));
handles.cellnum = (handles.levels^3 + 3*handles.levels^2 + 2*handles.levels)/6;
handles.vertnum = ((handles.levels+1)^3 + 3*(handles.levels+1)^2 + 2*(handles.levels+1))/6;
% Set values of s1, s2, s3 and s4
set(handles.s1, 'String', num2str(handles.cellnum));
set(handles.s2, 'String', num2str(handles.vertnum));
set(handles.s3, 'String', num2str(0.433*handles.edgelength^2));
set(handles.s4, 'String', ...
num2str(2*handles.cellnum*str2num(get(handles.s3, 'String'))));
% End of BLOCK
는 function e2_KeyPressFcn
뿐만 아니라 사용할 수 있도록 (BLOCK 묶인) 코드 블록을 참조 할 수 있는가? 이제 섹션을 function e2_KeyPressFcn
에 붙여 넣기 만하면되지만 매우 우아하지는 않습니다.
왜 당신은 당신의 새로운 기능에 모든 코드를 넣어 때 E1 또는 E2 변경 함수를 호출하지? –