找回密码
 注册
Simdroid-非首页
查看: 116|回复: 3

matlab的计算结果写进一个文本框里面?

[复制链接]
发表于 2011-4-21 17:18:46 | 显示全部楼层 |阅读模式 来自 中国
本帖最后由 xjtu 于 2011-4-23 18:14 编辑

请问如何将Design()中的计算结果写到data_out里面,即图中的等待设计计算区域?多排同时输入,如下面示例回调函数中的Result1和Result2一起输出。
界面图和程序段所示。
刚学MATLAB,请指点一下。

主程序

  1. %初始化根窗体   
  2. clf reset;   
  3. set(gcf,'Units','pixels','position' ,[185 50 860 655],'name', '设计计算',...   
  4.     'numbertitle', 'off', 'Tag', 'dsp');   
  5. set(gcf, 'defaultuicontrolfontsize' ,12);   
  6. set(gcf, 'defaultuicontrolfontname' , ' 隶书 ' );  
  7. %添加组件   
  8. %设计参数输入区域
  9. labelhead1 = uicontrol(gcf,'Style', 'text', 'String', '','Position', [29 80 125 525],...   
  10.     'BackgroundColor', [.5 .6 .6], 'FontSize', 12);  
  11. labelhead11 = uicontrol(gcf,'Style', 'text', 'String', '设计参数输入','Position', [30 610 120 20],...   
  12.     'BackgroundColor', [.8 .8 .8], 'FontSize', 14);   
  13. %设计结果输出区域   
  14. labelout = uicontrol(gcf,'Style', 'text', 'String', '设计结果输出','Position', [530 610 120 20],...   
  15.     'BackgroundColor', [.8 .8 .8], 'FontSize', 14);   
  16. data_out = uicontrol(gcf,'Style', 'edit', 'String', '等待设计计算','Position', [328 80 505 525],...
  17.     'BackgroundColor', [.6 .7 .9],'FontSize', 10);  
  18. %设计参数输入
  19. % 制冷量Qo
  20. label_Qo = uicontrol(gcf,'Style', 'text', 'String', '制冷量','Position', [30 570 60 20],...   
  21.     'BackgroundColor', [.5 .6 .6], 'FontSize', 12);   
  22. data_Qo = uicontrol(gcf,'Style', 'edit', 'String', '10','Position', [30 555 60 20], 'FontSize', 12);  
  23. label_Qo = uicontrol(gcf,'Style', 'text', 'String', 'kW','Position', [90 555 25 18],...   
  24.     'BackgroundColor', [.5 .6 .6], 'FontSize', 12);   
  25. % 热源温度th
  26. label_th = uicontrol(gcf,'Style', 'text', 'String', '热源温度','Position', [30 530 70 20],...   
  27.     'BackgroundColor', [.5 .6 .6], 'FontSize', 12);   
  28. data_th = uicontrol(gcf,'Style', 'edit', 'String', '85','Position', [30 515 60 20], 'FontSize', 12);
  29. label_th = uicontrol(gcf,'Style', 'text', 'String', '℃','Position', [90 515 18 17],...   
  30.     'BackgroundColor', [.5 .6 .6], 'FontSize', 12);  
  31. % 冷冻水进口温度tw
  32. label_tw = uicontrol('Style', 'text', 'String', '冷却水进口温度','Position', [30 490 120 20],...   
  33.     'BackgroundColor', [.5 .6 .6], 'FontSize', 12);   
  34. data_tw = uicontrol(gcf,'Style', 'edit', 'String', '32','Position', [30 475 60 20], 'FontSize', 12);
  35. label_tw = uicontrol(gcf,'Style', 'text', 'String', '℃','Position', [90 475 18 17],...   
  36.     'BackgroundColor', [.5 .6 .6], 'FontSize', 12);  
  37. % 冷冻水出口温度tc1
  38. label_tc1 = uicontrol(gcf,'Style', 'text', 'String', '冷冻水进口温度','Position', [30 450 120 20],...   
  39.     'BackgroundColor', [.5 .6 .6], 'FontSize', 12);   
  40. data_tc1 = uicontrol(gcf,'Style', 'edit', 'String', '11','Position', [30 435 60 20], 'FontSize', 12);  
  41. label_tc1 = uicontrol(gcf,'Style', 'text', 'String', '℃','Position', [90 435 18 17],...   
  42.     'BackgroundColor', [.5 .6 .6], 'FontSize', 12);  
  43. % 冷却水进口温度tc2
  44. label_tc2 = uicontrol(gcf,'Style', 'text', 'String', '冷冻水出口温度','Position', [30 410 100 20],...   
  45.     'BackgroundColor', [.5 .6 .6], 'FontSize', 12);   
  46. data_tc2 = uicontrol(gcf,'Style', 'edit', 'String', '8','Position', [30 395 60 20], 'FontSize', 12);  
  47. label_tc2 = uicontrol(gcf,'Style', 'text', 'String', '℃','Position', [90 395 18 17],...   
  48.     'BackgroundColor', [.5 .6 .6], 'FontSize', 12);  
  49. %用于计算的按钮   
  50. CalculateH = uicontrol(gcf,'Style', 'pushbutton', 'String', 'Calculate',...   
  51.     'Position', [125 30 70 30], 'FontSize', 10);
  52. %设置回叫函数
  53. set(CalculateH,'Callback', 'Design(data_Qo,data_th,data_tw,data_tc1,data_tc2)');
  54. Design(data_Qo,data_th,data_tw,data_tc1,data_tc2);  

复制代码
回叫函数(一个简单示例)

  1. function Result=Design(data_Qo,data_th,data_tw,data_tc1,data_tc2)
  2. Qo=str2num(get(data_Qo,'string'));
  3. th=str2num(get(data_th,'string'));
  4. tw=str2num(get(data_tw,'string'));
  5. tc1=str2num(get(data_tc1,'string'));
  6. tc2=str2num(get(data_tc2,'string'));  
  7. Result1=Qo/th+tw/tc1+tc2;
  8. Result2=Qo+th+tw+tc1+tc2;
复制代码
界面如下

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| 发表于 2011-4-23 10:37:43 | 显示全部楼层 来自 中国
Simdroid开发平台
怎么没人回应呀!!!
回复 不支持

使用道具 举报

发表于 2011-4-24 06:07:29 | 显示全部楼层 来自 英国
给你的输出窗口加一个TAG,然后Design函数直接findobj去set就行了。

假设你还想在”等待设计计算“那个位置显示结果,
可以先在界面主函数的定义里把data_out后面加上一个属性:
data_out = uicontrol(gcf,'Style', 'edit', 'String', '等待设计计算','Position', [328 80 505 525],...
    'BackgroundColor', [.6 .7 .9],'FontSize', 10, 'tag','OutputWindow');

然后稍微改动下Design函数,找到相应的Tag并显示结果:
function Design(data_Qo,data_th,data_tw,data_tc1,data_tc2)
OW=findobj('tag','OutputWindow');

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

strResult1=num2str(Qo/th+tw/tc1+tc2);
strResult2=num2str(Qo+th+tw+tc1+tc2);
OutputString=['Result1:   ',strResult1,'     Result2:   ',strResult2];
set(OW,'string',OutputString);
return

还有就是主程序最后一行应该删掉。

评分

1

查看全部评分

回复 不支持

使用道具 举报

 楼主| 发表于 2011-4-25 13:21:20 | 显示全部楼层 来自 中国
非常感谢!
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Simapps系列直播

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-10-4 21:26 , Processed in 0.039620 second(s), 17 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表