matlab功能块的作用,Matlab GUI重用功能块

我在GUIDE中创建了一个带有两个可编辑文本框和四个静态文本框的Matlab GUI

用户在两个可编辑的文本框(e1和e2)中输入值,并根据这些值计算应在静态文本框(s1,s2,s3和s4)中显示的值.

它在e1和e2的每个值变化上执行此操作

e1更改值时计算值的代码如下所示.

% --- 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

是否可以引用这段代码(包含在BLOCK中),以便函数e2_KeyPressFcn也可以使用它?

现在我只是将该部分复制粘贴到函数e2_KeyPressFcn,但这似乎不是很优雅.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值