求教!!!关于GUI得一个问题。我明天就要交了。。。
matlab吧
全部回复
仅看楼主
level 1
The_Ice_ 楼主
我设计了一个GUI用于工程计算 然而在读取数据的时候出现了问题
function [] = project
S.CNT = 0; % The number of times user pressed the pushbutton.
S.CHC = []; % Holds the strings which represent the operations performed.
S.fh = figure(
'unit',
'pix',
...
'position',[500 400 500 220],
...
'menub',
'no',
...
'name'
,'T-line Calculator, By Bojun Wu'
,
...
'numbertitle'
,'off'
,
...
'resize',
'off');
S.STR = {'falcon '
;'bluebird'
;'kiwi'
;'parrot'
;'finch'
};
% String for popups.
COL = get(S.fh,
'color');
S.pp = uicontrol(
'style',
'pop',
...
'unit',
'pix',
...
'position',[20 70 260 30],
...
'string',S.STR);
S.tx(10) = uicontrol(
'style',
'text',
...
'unit',
'pix',
...
'position',[20 105 140 20],
...
'string'
,'Choose your T-lines'
,
...
'backgroundcolor',COL);
S.pb = uicontrol(
'style',
'push',
...

2012年12月06日 03点12分 1
level 1
The_Ice_ 楼主

'unit',
'pix',
...
'posit',[20 20 260 30],
...
'string'
,'Get answer'
,
...
'callback',{@pb_call,S});
S.ed(1) = uicontrol(
'style',
'edit',
...
'unit',
'pix',
...
'position',[20 150 70 30],
...
'string',
'1');
S.tx(1) = uicontrol(
'style',
'text',
...
'unit',
'pix',
...
'position',[20 183 70 30],
...
'string'
,'Number of conductors'
,
...
'backgroundcolor',COL);
S.ed(2) = uicontrol(
'style',
'edit',
...
'unit',
'pix',
...
'position',[120 150 70 30],
...
'string',
'2');
S.tx(2) = uicontrol(
'style',
'text',
...
'unit',
'pix',
...
'position',[120 183 70 30],
...
'string'
,'Phase-phase distances'
,
...

2012年12月06日 03点12分 2
level 1
The_Ice_ 楼主

'backgroundcolor',COL);
S.ed(3) = uicontrol(
'style',
'edit',
...
'unit',
'pix',
...
'position',[220 150 70 30],
...
'string',
'3');
S.tx(3) = uicontrol(
'style',
'text',
...
'unit',
'pix',
...
'position',[220 183 70 30],
...
'string'
,'Bundle distance'
,
...
'backgroundcolor',COL);
S.ed(4) = uicontrol(
'style',
'edit',
...
'unit',
'pix',
...
'position',[370 150 70 30],
...
'string',
'R');
S.tx(4) = uicontrol(
'style',
'text',
...
'unit',
'pix',
...
'position',[370 183 70 30],
...
'string'
,'resistance ohms/ mile'
,
...
'backgroundcolor',COL);
S.ed(5) = uicontrol(
'style',
'edit',
...
'unit',
'pix',
...

2012年12月06日 03点12分 3
level 1
The_Ice_ 楼主

'position',[370 90 70 30],
...
'string',
'Xl');
S.tx(5) = uicontrol(
'style',
'text',
...
'unit',
'pix',
...
'position',[370 119 70 30],
...
'string'
,'reactance ohms/ mile'
,
...
'backgroundcolor',COL);
S.ed(6) = uicontrol(
'style',
'edit',
...
'unit',
'pix',
...
'position',[370 30 70 30],
...
'string',
'Xc');
S.tx(6) = uicontrol(
'style',
'text',
...
'unit',
'pix',
...
'position',[370 59 70 30],
...
'string'
,' admittance S/ mile'
,
...
'backgroundcolor',COL);
S.tx(7) = uicontrol(
'style',
'text',
...
'unit',
'pix',
...
'position',[360 15 90 13],
...
'string'
,'Made by Bojun Wu'
,
...
'backgroundcolor',COL);

2012年12月06日 03点12分 4
level 1
The_Ice_ 楼主
'unit','pix',...
'position',[10 90 70 30],...
'string','3');
S.tx(1) = uicontrol('style','text',...
'unit','pix',...
'position',[85 90 20 30],...
'string','+',...
'fontsize',16,...
'backgroundcolor',COL);
S.ed(2) = uicontrol('style','edit',...
'unit','pix',...
'position',[110 90 70 30],...
'string','2');
S.tx(2) = uicontrol('style','text',...
'unit','pix',...
'position',[185 90 20 30],...
'string','=',...
'fontsize',16,...
'backgroundcolor',COL);
S.ed(3) = uicontrol('style','edit',...
'unit','pix',...
'position',[220 90 70 30],...
'string','answer');
S.pb = uicontrol('style','push',...
'unit','pix',...
'position',[160 20 120 30],...
'string','Calculate');
set([S.pp,S.pb],'callback',{@pb_call,S});
function [] = pb_call(varargin)
% Callback for pushbutton
S = varargin{3}; % Get the structure.
N = str2double(get(S.ed(1:2),'string')); % Numbers from edits to op. on.
VL = get(S.pp,{'str','value'}); % User's choice from popup.
% Now get the string updates and perform operations.
switch VL{1}{VL{2}} % User's string choice.
case 'Add'
A = sum(N);
str = '+';
case 'Multiply'
A = prod(N);
str = 'x';
case 'Subtract'
A = -diff(N);
str = '-';
case 'Divide'
A = N(1)/N(2);
str = '/';
case 'Power'
A = N(1).^N(2);
str = '^';
otherwise
end
set(S.tx(1),'string',str) % Set the operation display.
if varargin{1}==S.pb % This stuff we only need to do if button is pushed.
S.CNT = S.CNT + 1;
set(S.ed(3),'str',A)
S.CHC{S.CNT,1} = sprintf('%2.2f %s %2.2f %s %2.2f',N(1),str,N(2),'=',A);
set(S.pb,'callback',{@pb_call,S})
set(S.fh,'deletefcn',{@fig_del,S})
end
function [] = fig_del(varargin)
S = varargin{3};
if ~isempty(S.STR)
assignin('base',S.STR,S.CHC) % Assign the data to the base workspace.
end
MATLAB得官网上得实例
同样使用了N=str2double(get(S.ed(1:2),
'string'));
一点问题都没有就。。
2012年12月06日 03点12分 6
1