24小时热门版块排行榜    

查看: 3275  |  回复: 6

hsli

铁虫 (小有名气)

[求助] Matlab之gui设计-如何将计算结果写入文本框?

请问如何将Design()中的计算结果写到data_out里面,即图中的等待设计计算区域?
界面图和程序段所示。
刚学MATLAB,请指点一下。



主程序段如下
CODE:
%初始化根窗体   
clf reset;   
set(gcf,'Units','pixels','position' ,[185 50 860 655],'name', '设计计算',...   
    'numbertitle', 'off', 'Tag', 'dsp');   
set(gcf, 'defaultuicontrolfontsize' ,12);   
set(gcf, 'defaultuicontrolfontname' , ' 隶书 ' );  

%添加组件   
%设计参数输入区域
labelhead1 = uicontrol(gcf,'Style', 'text', 'String', '','Position', [29 80 125 525],...   
    'BackgroundColor', [.5 .6 .6], 'FontSize', 12);  
labelhead11 = uicontrol(gcf,'Style', 'text', 'String', '设计参数输入','Position', [30 610 120 20],...   
    'BackgroundColor', [.8 .8 .8], 'FontSize', 14);   

%设计结果输出区域   
labelout = uicontrol(gcf,'Style', 'text', 'String', '设计结果输出','Position', [530 610 120 20],...   
    'BackgroundColor', [.8 .8 .8], 'FontSize', 14);   
data_out = uicontrol(gcf,'Style', 'edit', 'String', '等待设计计算','Position', [328 80 505 525],...
    'BackgroundColor', [.6 .7 .9],'FontSize', 10);  
%设计参数输入
% 制冷量Qo
label_Qo = uicontrol(gcf,'Style', 'text', 'String', '制冷量','Position', [30 570 60 20],...   
    'BackgroundColor', [.5 .6 .6], 'FontSize', 12);   
data_Qo = uicontrol(gcf,'Style', 'edit', 'String', '10','Position', [30 555 60 20], 'FontSize', 12);  
label_Qo = uicontrol(gcf,'Style', 'text', 'String', 'kW','Position', [90 555 25 18],...   
    'BackgroundColor', [.5 .6 .6], 'FontSize', 12);   

% 热源温度th
label_th = uicontrol(gcf,'Style', 'text', 'String', '热源温度','Position', [30 530 70 20],...   
    'BackgroundColor', [.5 .6 .6], 'FontSize', 12);   
data_th = uicontrol(gcf,'Style', 'edit', 'String', '85','Position', [30 515 60 20], 'FontSize', 12);
label_th = uicontrol(gcf,'Style', 'text', 'String', '℃','Position', [90 515 18 17],...   
    'BackgroundColor', [.5 .6 .6], 'FontSize', 12);  

% 冷冻水进口温度tw
label_tw = uicontrol('Style', 'text', 'String', '冷却水进口温度','Position', [30 490 120 20],...   
    'BackgroundColor', [.5 .6 .6], 'FontSize', 12);   
data_tw = uicontrol(gcf,'Style', 'edit', 'String', '32','Position', [30 475 60 20], 'FontSize', 12);
label_tw = uicontrol(gcf,'Style', 'text', 'String', '℃','Position', [90 475 18 17],...   
    'BackgroundColor', [.5 .6 .6], 'FontSize', 12);  

% 冷冻水出口温度tc1
label_tc1 = uicontrol(gcf,'Style', 'text', 'String', '冷冻水进口温度','Position', [30 450 120 20],...   
    'BackgroundColor', [.5 .6 .6], 'FontSize', 12);   
data_tc1 = uicontrol(gcf,'Style', 'edit', 'String', '11','Position', [30 435 60 20], 'FontSize', 12);  
label_tc1 = uicontrol(gcf,'Style', 'text', 'String', '℃','Position', [90 435 18 17],...   
    'BackgroundColor', [.5 .6 .6], 'FontSize', 12);  

% 冷却水进口温度tc2
label_tc2 = uicontrol(gcf,'Style', 'text', 'String', '冷冻水出口温度','Position', [30 410 100 20],...   
    'BackgroundColor', [.5 .6 .6], 'FontSize', 12);   
data_tc2 = uicontrol(gcf,'Style', 'edit', 'String', '8','Position', [30 395 60 20], 'FontSize', 12);  
label_tc2 = uicontrol(gcf,'Style', 'text', 'String', '℃','Position', [90 395 18 17],...   
    'BackgroundColor', [.5 .6 .6], 'FontSize', 12);  

%用于计算的按钮   
CalculateH = uicontrol(gcf,'Style', 'pushbutton', 'String', 'Calculate',...   
    'Position', [125 30 70 30], 'FontSize', 10);

%设置回叫函数   
set(CalculateH,'Callback', 'Design(data_Qo,data_th,data_tw,data_tc1,data_tc2)');
Design(data_Qo,data_th,data_tw,data_tc1,data_tc2);  

示例的回调函数如下
CODE:
function Result=Design(data_Qo,data_th,data_tw,data_tc1,data_tc2)

Qo=str2num(get(data_Qo,'string'));
th=str2num(get(data_th,'string'));
tw=str2num(get(data_tw,'string'));
tc1=str2num(get(data_tc1,'string'));
tc2=str2num(get(data_tc2,'string'));  

Result=Qo+th+tw+tc1+tc2;

[ Last edited by hsli on 2011-4-22 at 18:24 ]
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

hsli

铁虫 (小有名气)

自己顶一下!
2楼2011-04-23 15:13:08
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

hsli

铁虫 (小有名气)

输出至少要求两排,如示例的回调函数中的tc2和Result一起同时显示在文本框中。
3楼2011-04-23 18:41:37
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

hsli

铁虫 (小有名气)

以解决,谢谢各位围观!
4楼2011-04-25 12:48:15
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

yqx1985

木虫 (著名写手)

云中仙

【答案】应助回帖

感谢参与,应助指数 +1
同学,你真是a q,就我围观了
人面不知何时去,桃花依旧笑春风
5楼2012-04-14 01:01:27
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

格物要致知

木虫 (著名写手)

【答案】应助回帖


感谢参与,应助指数 +1
臭水沟: 金币+1, 谢谢交流~~ 2012-04-15 10:35:31
将结果存储到一个string的变量中(比如str),然后设置“等待计算结果”,假设“等待计算结果”这个控件的名字是result,那么就是set(handles.result,'string',str)
格物致知专做科研
6楼2012-04-14 13:29:03
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

格物要致知

木虫 (著名写手)

【答案】应助回帖

不得不说你这样写界面好麻烦啊
格物致知专做科研
7楼2012-04-14 13:29:51
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 hsli 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 投票:  有多少人是今天查系统知道结果的? +16 爱看书的可乐 2026-08-26 18/900 2026-08-28 14:36 by winsaint
[基金申请] 2026年叶企孙基金 +3 bud_bud 2026-08-27 6/300 2026-08-28 11:53 by bud_bud
[基金申请] 国自然面上复盘~欢迎讨论 (金币+5) +12 晴天加油 2026-08-26 13/650 2026-08-28 11:32 by skyjudy
[基金申请] 基金系统什么内容也没有 30+4 winsaint 2026-08-27 9/450 2026-08-28 11:06 by maolC
[基金申请] 哪位高人中了,把查询到的截图贴出来让我看看,让我长长见识 +5 yuleib84 2026-08-26 6/300 2026-08-28 00:02 by yudaoqian88
[基金申请] 申请删除本帖 +6 lyz123lyz 2026-08-27 7/350 2026-08-27 17:31 by 宁静致远sy
[基金申请] 看板上这么多中的,有点像50人群里49个人都是骗子的那种感觉…… +5 a089 2026-08-26 6/300 2026-08-27 14:05 by jonewore
[文学芳草园] 梦想 +3 myrtle 2026-08-26 3/150 2026-08-27 10:01 by angelyueyi
[基金申请] 2026国自然函评费到账 +22 羊腰板 2026-08-21 25/1250 2026-08-26 15:00 by zuocuiping
[基金申请] 2026年8月25日国自然放榜前突然收到列入评审专家邮件,有关系吗? +25 木水思豆 2026-08-25 28/1400 2026-08-26 14:53 by draco1987
[基金申请] 国合里面能看到了 +7 一怀馨秋 2026-08-26 7/350 2026-08-26 11:23 by zhaosm1982
[基金申请] 国际合作可查了,中了面上 (EPI+1)(金币+50) +18 Ldrop2023 2026-08-26 18/900 2026-08-26 11:15 by cmrandy
[基金申请] 系统进不去 +4 yanglien 2026-08-26 5/250 2026-08-26 11:10 by wenfengw83
[基金申请] 项目信息和经费信息在系统里都可以看到了 +6 wittyboy 2026-08-26 14/700 2026-08-26 10:55 by wittyboy
[基金申请] 国合可查了 +3 paperzjh 2026-08-26 3/150 2026-08-26 10:41 by LemmonTr
[基金申请] 今天务委会开完了,明天出结果吗 +19 angus9576 2026-08-25 23/1150 2026-08-26 10:03 by zp519
[基金申请] 国合现在查不到了吗? +10 chengyan1220 2026-08-24 20/1000 2026-08-26 08:57 by peasantsprig
[基金申请] 明天应该可查了!? +6 chengyan1220 2026-08-23 6/300 2026-08-25 19:45 by zfd97
[基金申请] 没有任何消息-是不是就凉了 +9 图啦图啦 2026-08-24 10/500 2026-08-25 11:59 by 南海小哥
[基金申请] 建议基金发布提前给出明确的时间点 +13 kulium 2026-08-21 16/800 2026-08-24 16:27 by superceng
信息提示
请填处理意见