No BSD License  

Highlights from
Neurocal

image thumbnail
from Neurocal by Zeng Lertmanorat
Simulation describing the electrical activity of nerve cell (neuron) by solving cable equation

gui_channel(varargin)
function gui_channel(varargin)
global zeng2
if nargin==0
   action = 'initial';
else
   action = varargin{1};
end
switch action
case 'initial'
    if length(zeng2.var)==0;
        zexst('err','You have no variable to set.')
        return
    end
    temp=findobj('type','figure','tag','gui_channel');
    if ~isempty(temp);
        PointerLocation=get(0,'PointerLocation');
        FG_Size=[PointerLocation(1) 0 220 100];
        FG_Size(2)=PointerLocation(2)-FG_Size(4)-10;
        figure(temp)
        return
    end
    varnumber=1;
    temp=find(zeng2.var{varnumber}.name=='{');
    if isempty(temp)
        eval(['global ' zeng2.var{varnumber}.name])
    else
        eval(['global ' zeng2.var{varnumber}.name(1:(temp-1))])
    end
    %Needed for compiling reason
    Temppara=[];
    %---------------------------
    eval(['Temppara=' zeng2.var{varnumber}.name ';'])
    GUIch.parent=varargin{2};
    parent_size=get(GUIch.parent,'position');
    if parent_size(2)<400
        temp=    parent_size(2)+30+116+70;
    else
        temp=    parent_size(2)-30-116-100-20;
    end;
    FG_Size=[parent_size(1) temp  220 100];
    GUIch.figure = figure('Color',[0.8 0.8 0.8], ...
            'MenuBar','none',...
            'Name','Setting:Channels',...
            'NumberTitle','off',...
        	'Position',FG_Size, ...
            'resize','off',...
            'tag','gui_channel',...
        	'ToolBar','none');
    set(GUIch.figure,'position',FG_Size)
    FG_Backgournd=get(GUIch.figure,'Color');
    uicontrol('Parent',GUIch.figure, ...
            'Units','pixel', ...
    	    'BackgroundColor',[0.85 0.8 0.75], ...
            'callback','gui_channel(''okay'')',...
    	    'ListboxTop',0, ...
	        'Position',[25 5 50 22], ...
            'String','Ok', ...
	        'Tag','Pushbutton');
    uicontrol('Parent',GUIch.figure, ...
            'Units','pixel', ...
    	    'BackgroundColor',[0.85 0.8 0.75], ...
            'callback','delete(gcbf)',...
    	    'ListboxTop',0, ...
	        'Position',[85 5 50 22], ...
    	    'String','Close', ...
	        'Tag','Pushbutton');
    uicontrol('Parent',GUIch.figure, ...
            'Units','pixel', ...
    	    'BackgroundColor',[0.85 0.8 0.75], ...
            'callback','gui_channel(''okay'',''apply'')',...
    	    'ListboxTop',0, ...
	        'Position',[145 5 50 22], ...
    	    'String','Apply', ...
	        'Tag','Pushbutton');
    var_string=cell(1,length(zeng2.var));
    for i=1:length(zeng2.var)
        var_string{i}=zeng2.var{i}.name;
    end
    GUIch.vartext=uicontrol('Parent',GUIch.figure, ...
    	    'BackgroundColor',FG_Backgournd, ...
	        'HorizontalAlignment','right', ...
    	    'ListboxTop',0, ...
	        'Position',[10 FG_Size(4)-25 60 22], ...
    	    'String','Variable :', ...
	        'Style','text', ...
    	    'Tag','StaticText1');        
    GUIch.var = uicontrol('Parent',GUIch.figure, ...
    	    'BackgroundColor',[1 1 1], ...
            'callback','gui_channel(''update number'');',...
    	    'ListboxTop',0, ...
	        'Position',[114 FG_Size(4)-25 85 22], ...
            'string',var_string,...
    	    'Style','popupmenu', ...
    	    'Tag','pop_var');
    GUIch.label = uicontrol('Parent',GUIch.figure, ...
	   	    'BackgroundColor',[0.8 0.8 0.8], ...
            'HorizontalAlignment','right', ...
	        'ListboxTop',0, ...
    	    'Position',[8 FG_Size(4)-55 192 23], ...
	        'String',' Current    G ( 1/(kohm-cm2))       E (mV)', ...
    	    'Style','text', ...
	        'Tag','StaticText2');
    GUIch.text=[];
    GUIch.G=[];
    GUIch.E=[];
    GUIch.I_length=0;
    set(GUIch.figure,'userdata',GUIch)
    gui_channel('update',GUIch.figure,varnumber);
    
case 'update number'
    gui_channel('update',gcbf,get(gcbo,'value'));
case 'update'
    GUIch=get(varargin{2},'userdata');
    varnumber=varargin{3};
    var_string=cell(1,length(zeng2.var));
    for i=1:length(zeng2.var)
        var_string{i}=zeng2.var{i}.name;
    end
    
    temp=find(zeng2.var{varnumber}.name=='{');
    if isempty(temp)
        eval(['global ' zeng2.var{varnumber}.name])
    else
        eval(['global ' zeng2.var{varnumber}.name(1:(temp-1))])
    end
    eval(['Temppara=' zeng2.var{varnumber}.name ';'])

    if isempty(Temppara.model)
        I_length=0;
    else
        I_length=length(Temppara.model.I);
    end
    
    %FG_Size=[PointerLocation(1) 0 220 100];
    FG_Size=get(GUIch.figure,'position');
    FG_Size(2)=FG_Size(2)+(GUIch.I_length-I_length)*25;
    FG_Size(4)=100+I_length*25;
    GUIch.I_length=I_length;

    set(GUIch.var,   'string',var_string,'value',varnumber);
    set(GUIch.figure,'position',FG_Size);
    set(GUIch.vartext,'Position',[10 FG_Size(4)-25 60 22])
    set(GUIch.var,'Position',[114 FG_Size(4)-25 85 22])
    set(GUIch.label,'Position',[8 FG_Size(4)-55 192 23])
    if ~isempty(GUIch.G)
        delete([GUIch.text GUIch.G GUIch.E]);
        GUIch.text=[];
        GUIch.G=[];
        GUIch.E=[];
    end
    if  GUIch.I_length
        FG_Backgournd=get(GUIch.figure,'Color');
        for i=1:GUIch.I_length;
            GUIch.text(i)=uicontrol('Parent',GUIch.figure, ...
	            'BackgroundColor',FG_Backgournd, ...
	            'HorizontalAlignment','right', ...
	            'ListboxTop',0, ...
	            'Position',[5 40+(GUIch.I_length-i)*25 60 22], ...
	            'String',[Temppara.model.I{i}.name ' : '], ...
	            'Style','text', ...
	            'Tag','StaticText1');        
            GUIch.G(i) = uicontrol('Parent',GUIch.figure, ...
	            'BackgroundColor',[1 1 1], ...
	            'ListboxTop',0, ...
	            'Position',[70 40+(GUIch.I_length-i)*25 65 22], ...
                'string',num2str(Temppara.model.I{i}.G),...
	            'Style','edit', ...
	            'Tag','EditText1');
            GUIch.E(i) = uicontrol('Parent',GUIch.figure, ...
	            'BackgroundColor',[1 1 1], ...
	            'ListboxTop',0, ...
	            'Position',[140 40+(GUIch.I_length-i)*25 65 22], ...
                'string',num2str(Temppara.model.I{i}.E),...
	            'Style','edit', ...
	            'Tag','EditText1');
        end
    end
    set(GUIch.figure,'userdata',GUIch);
    
case 'check value'
    GUIch=get(gcbf,'userdata');
    
    if GUIch.I_length
    
        varnumber=get(GUIch.var,'value');
    
        temp=find(zeng2.var{varnumber}.name=='{');

        if isempty(temp)
            eval(['global ' zeng2.var{varnumber}.name])
        else
            eval(['global ' zeng2.var{varnumber}.name(1:(temp-1))])
        end
        eval(['Tempparamodel=' zeng2.var{varnumber}.name '.model;'])

        for i=1:GUIch.I_length
            G=str2num(get(GUIch.G(i),'string'));
            if isempty(G)| ~isreal(G)
                zexst('err',['Please give a reasonable value for G' Tempparamodel.I{i}.name]);
                return
            else
                eval([zeng2.var{varnumber}.name '.model.I{i}.G =G;']);
            end
            

            E=str2num(get(GUIch.E(i),'string'));
            if isempty(E)| ~isreal(E)
                zexst('err',['Please give a reasonable value for E' Tempparamodel.I{i}.name]);
                return
            else
                eval([zeng2.var{varnumber}.name '.model.I{i}.E =E;']);
            end
            
        end
    
    end
    
case 'okay'
    gui_channel('check value');
    GUIch=get(gcbf,'userdata');
    if nargin==1
        %from okay
    else        
        %from apply
        zexst('calculate')
    end
end

Contact us at files@mathworks.com