Code covered by the BSD License  

Highlights from
3D Surface Plots from Excel Data GUI

image thumbnail

3D Surface Plots from Excel Data GUI

by

Christopher Rouxel

 

12 Jul 2010 (Updated )

Upload data from Excel and plot in 3D as a scatter plot, lsq curve fit, contour plot and others.

MainGUI(varargin)
function varargout = MainGUI(varargin)

% Copyright (c) 2010, Christopher Rouxel
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
%     * Redistributions of source code must retain the above copyright
%       notice, this list of conditions and the following discla(handles.axes1)imer.
%     * Redistributions in binary form must reproduce the above copyright
%       notice, this list of conditions and the following discla(handles.axes1)imer in
%       the documentation and/or other materials provided with the distribution
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DIScla(handles.axes1)IMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.





% MAINGUI M-file for mainGui.fig
%      MAINGUI, by itself, creates a new MAINGUI or raises the existing
%      singleton*.
%
%      H = MAINGUI returns the handle to a new MAINGUI or the handle to
%      the existing singleton*.
%
%      MAINGUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MAINGUI.M with the given input arguments.
%
%      MAINGUI('Property','Value',...) creates a new MAINGUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before mainGui_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to mainGui_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help mainGui

% Last Modified by GUIDE v2.5 12-Jul-2010 19:34:23

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @mainGui_OpeningFcn, ...
    'gui_OutputFcn',  @mainGui_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before mainGui is made visible.
function mainGui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figureword
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to mainGui (see VARARGIN)

% Choose default command line output for mainGui
handles.output = hObject;

%Global Counter of surfaces
handles.buttonCounter = 0;

handles.Iupper=eye(101);
handles.Ilower=eye(101);


handles.Xretained1=eye(101);
handles.Xretained2=eye(101);

handles.Yretained1=eye(101);
handles.Yretained2=eye(101);

handles.Zretained1=eye(101);
handles.Zretained2=eye(101);






set(handles.text7,'String','0','FontSize',30);


% Update handles structure
guidata(hObject, handles);
set(hObject,'toolbar','figure');
% UIWAIT makes mainGui wait for user response (see UIRESUME)
% uiwait(handles.figure1);

hold(handles.axes2,'off')
RRG=imread('RRGLogo.gif');
imshow(RRG,'Parent',handles.axes2);


% --- Outputs from this function are returned to the command line.3
function varargout = mainGui_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbuttonLoadXLS.
function pushbuttonLoadXLS_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonLoadXLS (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


handles.fileName=uigetfile('*.xls');
guidata(hObject,handles)

setPopupmenuString(handles.popupmenuX, eventdata, handles)
setPopupmenuString(handles.popupmenuY, eventdata, handles)
setPopupmenuString(handles.popupmenuZ, eventdata, handles)

set(handles.popupmenuX,'value',1);
set(handles.popupmenuY,'value',2);
set(handles.popupmenuZ,'value',3);

xColNum  = get(handles.popupmenuX,'value');
yColNum  = get(handles.popupmenuY,'value');
zColNum = get(handles.popupmenuZ,'value');


fileName = handles.fileName;

[x, y,AA,ogXColSize,ogYColSize,a]= readExcelColumns(fileName,xColNum,yColNum);
[x, z,AA,ogXColSize,ogYColSize,a]= readExcelColumns(fileName,xColNum,zColNum);






% surf(handles.axes1,x,y,z)
%    XNames=get(handles.popupmenuX,'string');
%         YNames=get(handles.popupmenuY,'string');
%         ZNames=get(handles.popupmenuZ,'string');
%         xlabel(XNames(xColNum)),ylabel(YNames(yColNum)),zlabel(ZNames(zColNum));
%
%
% title(handles.axes1,fileName,'FontSize',16,'Color','r','background','black')


% --- Executes on selection change in popupmenuX.
function popupmenuX_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenuX (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenuX contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenuX


xColNum  = get(handles.popupmenuX,'value');
yColNum  = get(handles.popupmenuY,'value');
zColNum = get(handles.popupmenuZ,'value');

fileName = handles.fileName;

[x, y,AA,ogXColSize,ogYColSize,a]= readExcelColumns(fileName,xColNum,yColNum);
'popupmenuX';

popupmenuPlot_Callback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function popupmenuX_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenuX (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



% --- Executes on selection change in popupmenuY.
function popupmenuY_Callback(hObject, eventdata, handles)

% hObject    handle to popupmenuY (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenuY contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenuY


xColNum  = get(handles.popupmenuX,'value');
yColNum  = get(handles.popupmenuY,'value');
zColNum = get(handles.popupmenuZ,'value');

fileName = handles.fileName;
'popupmenY';
[x, y,AA,ogXColSize,ogYColSize,a]= readExcelColumns(fileName,xColNum,yColNum);

popupmenuPlot_Callback(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function popupmenuY_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenuY (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in popupmenuZ.
function popupmenuZ_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenuZ (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenuZ contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenuZ

xColNum  = get(handles.popupmenuX,'value');

zColNum = get(handles.popupmenuZ,'value');

fileName = handles.fileName;
'popmemnuZ';

[x, z,AA,ogXColSize,ogYColSize,a]= readExcelColumns(fileName,xColNum,zColNum);

popupmenuPlot_Callback(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function popupmenuZ_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenuZ (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in popupmenuPlot.
function popupmenuPlot_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenuPlot (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenuPlot contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenuPlot
guidata(hObject, handles);

A=get(handles.radiobutton4,'value')

if A==0
    handles.buttonCounter =1;
    set(handles.text7,'String',num2str(handles.buttonCounter) );
    guidata(hObject, handles); %without this line, the handles structure would not update,
    %and the counter would not increment
    
end

if A==1
    
    handles.buttonCounter = handles.buttonCounter + 1;
    set(handles.text7,'String',num2str(handles.buttonCounter) );
    guidata(hObject, handles); %without this line, the handles structure would not update,
    %and the counter would not increment
end



guidata(hObject,handles)

xColNum  = get(handles.popupmenuX,'value');
yColNum  = get(handles.popupmenuY,'value');
zColNum = get(handles.popupmenuZ,'value');

fileName = handles.fileName;

[x, y,AA,ogXColSize,ogYColSize,a]= readExcelColumns(fileName,xColNum,yColNum);
[x, z,AA,ogXColSize,ogYColSize,a]= readExcelColumns(fileName,xColNum,zColNum);

[xr,xc]=size(x);
bigx=zeros(xr*xc,1);
bigy=bigx;
bigz=bigx;

for i=1:xc
    for j=1:xr
        bigx((i-1)*10+j,1)=x(j,i);
        bigy((i-1)*10+j,1)=y(j,i);
        bigz((i-1)*10+j,1)=z(j,i);
        
    end
end


data=[bigx'; bigy'];

a0 = [0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.0]; % Starting guess

options=optimset('MaxFunEvals',100000,'TolFun',1e-10,'MaxIter',10000);

bigz'
[a, resnorm] = lsqcurvefit(@myfun, a0, data, bigz',[],[],options);


deltaX=(max(x)-min(x))/100;%was .1 when ganesh did it

deltaY=(max(y)-min(y))/100;%was .1 when ganesh did it

gX=min(x):deltaX:max(x);
gY=min(y):deltaY:max(y);

[X,Y]=meshgrid(gX,gY);


Z = a(1)*X+ a(2)*X.^2 + a(3)*X.^3+a(4)*Y + a(5)*Y.^2 + a(6)*Y.^3+a(7)*X.*Y+a(8);
'handles.buttonCounter'
A=handles.buttonCounter
if A==1
    handles.Xretained1=X;
    handles.Yretained1=Y;
    handles.Zretained1=Z;
end
if A==2
    handles.Xretained2=X;
    handles.Yretained2=Y;
    handles.Zretained2=Z;
end

guidata(hObject,handles)

XNames=get(handles.popupmenuX,'string');
YNames=get(handles.popupmenuY,'string');
ZNames=get(handles.popupmenuZ,'string');


fileName = handles.fileName;

AA=char(XNames(xColNum));
BB=char(YNames(yColNum));
CC=char(ZNames(zColNum));
DD=char(fileName);

sAA=size(AA);
sBB=size(BB);
sCC=size(CC);
sDD=size(DD)
if sAA(2)>5
    AA=AA(1:5);
end

if sBB(2)>5
    BB=BB(1:5);
end

if sCC(2)>5
    CC=CC(1:5);
end

if sDD(2)>5
    DD=DD(1:5);
end

plotName=strcat(DD,' _ ',AA,' vs.',BB,' vs. ',CC)

     
        XNames=get(handles.popupmenuX,'string');
        YNames=get(handles.popupmenuY,'string');
        ZNames=get(handles.popupmenuZ,'string');
        
        xlabel(XNames(xColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        ylabel(YNames(yColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        zlabel(ZNames(zColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        
        
        
        title(handles.axes1,fileName,'FontSize',24,'Color','black','background','white','EdgeColor','black')

switch get(handles.popupmenuPlot,'Value')
    
    
    
    case 2  %Scatter
          
        checkhold=get(handles.radiobutton4,'value')%hold button
        if checkhold==0
            'Hold is off so clear'
            cla(handles.axes1);
            hold(handles.axes1,'on')
        else
            hold(handles.axes1,'on');
           end
        
           
        plot3(x,y,z,'.','MarkerSize',15,'parent',handles.axes1,'HandleVisibility','on')
        grid on
        
        XNames=get(handles.popupmenuX,'string');
        YNames=get(handles.popupmenuY,'string');
        ZNames=get(handles.popupmenuZ,'string');
        
        xlabel(XNames(xColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        ylabel(YNames(yColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        zlabel(ZNames(zColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        
        
        
        title(handles.axes1,fileName,'FontSize',24,'Color','black','background','white','EdgeColor','black')
          
        if  checkhold==0
            'hold off';
            hold off;
        
        end
    case 3 %3D plot
        % stem3(x,y,z,'parent',handles.axes1)
        
        set(handles.axes1,'XGrid','on','YGrid','on','ZGrid','on')
        
        
        guidata(hObject,handles)
        checkhold=get(handles.radiobutton4,'value')%hold button
        if checkhold==0
            'Hold is off so clear'
            cla(handles.axes1);
            hold(handles.axes1,'on')
        else
            hold(handles.axes1,'on');
        end
        
        axis tight;
   
        view(40,80)
        surf(X,Y,Z,'parent',handles.axes1,'HandleVisibility','on');
        
        
        'lines';
        lx=[X(1);X(1)+((max(max(x))-min(min(x)))+.001)*1];
        ly=[y(1);Y(1)+((max(max(y))-min(min(y)))+.001)*1];
        lz=[Z(1);Z(1)+((max(max(Z))-min(min(Z))) +.001)*.5];
        line(lx,ly,lz,'LineWidth',4,'parent',handles.axes1);
        
        
        text(lx(2),ly(2),lz(2),plotName,'parent',handles.axes1,'HorizontalAlignment','center',...
            'BackgroundColor',[.7 .9 .7]);
        
        
        XNames=get(handles.popupmenuX,'string');
        YNames=get(handles.popupmenuY,'string');
        ZNames=get(handles.popupmenuZ,'string');
      
        xlabel(XNames(xColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        ylabel(YNames(yColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        zlabel(ZNames(zColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        title(handles.axes1,fileName,'FontSize',24,'Color','black','background','white','EdgeColor','black');
        
        axis auto
        
        colormap jet;
        
        checktol=get(handles.checkbox3,'value')%tolerance button
        if checktol==1
            
            Tol=str2double(get(handles.TolEdit,'String'))
            
            if Tol>1 || Tol<0 ||isnan(Tol)==1
                'dialogue'
                helpdlg('Value must be between 0 and 1','Tolerance Input Error');
            else
                hold(handles.axes1,'on')
                handles.Iupper=surf(X,Y,Z+Z.*Tol,'parent',handles.axes1,'facealpha',.2);
                handles.Ilower=surf(X,Y,Z-Z.*Tol,'parent',handles.axes1,'facealpha',.2);
                
                %alpha(handles.Ilower,.5)
                %alpha(handles.Iupper,.2)
            end
        end
        
        %
        if  checkhold==0
            'hold off';
            hold off;
        end
        %
        guidata(hObject, handles)
       
    
    
    case 4 %3D plot, B&W
        % stem3(x,y,z,'parent',handles.axes1)
        
        set(handles.axes1,'XGrid','on','YGrid','on','ZGrid','on')
        
        
        guidata(hObject,handles)
        checkhold=get(handles.radiobutton4,'value')%hold button
        if checkhold==0
            'Hold is off so clear'
            cla(handles.axes1);
            hold(handles.axes1,'on')
        else
            hold(handles.axes1,'on');
        end
        
        axis tight;
   
        
        mesh(X,Y,Z,'parent',handles.axes1,'HandleVisibility','on');
        
        
        'lines';
        lx=[X(1);X(1)+((max(max(x))-min(min(x)))+.001)*1];
        ly=[y(1);Y(1)+((max(max(y))-min(min(y)))+.001)*1];
        lz=[Z(1);Z(1)+((max(max(Z))-min(min(Z))) +.001)*.5];
        line(lx,ly,lz,'LineWidth',4,'parent',handles.axes1);
        
        
        text(lx(2),ly(2),lz(2),plotName,'parent',handles.axes1,'HorizontalAlignment','center',...
            'BackgroundColor',[.7 .9 .7]);
        
        
        XNames=get(handles.popupmenuX,'string');
        YNames=get(handles.popupmenuY,'string');
        ZNames=get(handles.popupmenuZ,'string');
        xlabel(XNames(xColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        ylabel(YNames(yColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        zlabel(ZNames(zColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        title(handles.axes1,fileName,'FontSize',24,'Color','black','background','white','EdgeColor','black')
        axis auto
        
        colormap bone;
        
        checktol=get(handles.checkbox3,'value')%tolerance button
        if checktol==1
            
            Tol=str2double(get(handles.TolEdit,'String'))
            
            if Tol>1 || Tol<0 ||isnan(Tol)==1
                'dialogue'
                helpdlg('Value must be between 0 and 1','Tolerance Input Error');
            else
                hold(handles.axes1,'on')
                handles.Iupper=surf(X,Y,Z+Z.*Tol,'parent',handles.axes1,'facealpha',.2);
                handles.Ilower=surf(X,Y,Z-Z.*Tol,'parent',handles.axes1,'facealpha',.2);
                
                %alpha(handles.Ilower,.5)
                %alpha(handles.Iupper,.2)
            end
        end
        
        %
        if  checkhold==0
            'hold off';
            hold off;
        end
        %
        guidata(hObject, handles)
        
        
        
        
    case 5 %3D plot, Normalized
        checkhold=get(handles.radiobutton4,'value')%tolerance button
        if checkhold==0
            
            cla(handles.axes1);
            hold(handles.axes1,'on')
        end
        hold(handles.axes1,'on')
        
        set(handles.axes1,'XGrid','on','YGrid','on','ZGrid','on')

        axis auto
        colormap jet;
        
        
        Z=(Z-min(min(Z)))/(max(max(Z))-min(min(Z)));
        min(Z)
        
        surf(X,Y,Z,'parent',handles.axes1,'HandleVisibility','on','AlphaData',.4)
        
        lx=[X(1,1);X(1)+((max(max(x))-min(min(x)))+.001)*1];
        ly=[y(1);y(1)+((max(max(y))-min(min(y)))+.001)*1];
        lz=[Z(1);Z(1)+((max(max(Z))-min(min(Z)))+.001)*.5];
        
        
        line(lx,ly,lz,'LineWidth',4,'parent',handles.axes1);
        
        % line([0 1],[0 1],[0 1],'LineWidth',4,'parent',handles.axes1);
        
        text(lx(2),ly(2),lz(2),plotName,'parent',handles.axes1,'HorizontalAlignment','center',...
            'BackgroundColor',[.7 .9 .7]);
        
        
        axis auto
        
        XNames=get(handles.popupmenuX,'string');
        YNames=get(handles.popupmenuY,'string');
        ZNames=get(handles.popupmenuZ,'string');
       
          xlabel(XNames(xColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        ylabel(YNames(yColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        zlabel(ZNames(zColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        
       title(handles.axes1,fileName,'FontSize',24,'Color','black','background','white','EdgeColor','black')
        
        if  checkhold==0
            hold off;
        else
            hold(handles.axes1,'on')
        end
        
    case 6 %Contour Map
        checkhold=get(handles.radiobutton4,'value')%tolerance button
        if checkhold==0
            cla(handles.axes1);
        end
        hold(handles.axes1,'on');
        
        axis auto
        
        [wham, bam]=contour(X,Y,Z,'parent',handles.axes1);
        clabel(wham, bam)
        grid on
        
        XNames=get(handles.popupmenuX,'string');
        YNames=get(handles.popupmenuY,'string');
        ZNames=get(handles.popupmenuZ,'string');
         
        
        xlabel(XNames(xColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        ylabel(YNames(yColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        zlabel(ZNames(zColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        
        title(handles.axes1,fileName,'FontSize',24,'Color','black','background','white','EdgeColor','black')
        
        if  checkhold==0
            hold off;
        end
        
        
    case 7 %3D contour map
        checkhold=get(handles.radiobutton4,'value')%tolerance button
        if checkhold==0
            
            cla(handles.axes1);
        end
        hold(handles.axes1,'on');
        
        grid on
        
        [wham, bam]=contour3(X,Y,Z,'parent',handles.axes1);
        clabel(wham, bam,'Color','black','background','white','edgecolor','black','margin',5)
        XNames=get(handles.popupmenuX,'string');
        YNames=get(handles.popupmenuY,'string');
        ZNames=get(handles.popupmenuZ,'string');
        
          xlabel(XNames(xColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        ylabel(YNames(yColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        zlabel(ZNames(zColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        
        title(handles.axes1,fileName,'FontSize',24,'Color','black','background','white','EdgeColor','black')
        
        
        if  checkhold==0
            hold off;
        end
        
        
         case 8%Delaunay Triangulation
        
        set(handles.axes1,'XGrid','on','YGrid','on','ZGrid','on')
        
        
        guidata(hObject,handles)
        checkhold=get(handles.radiobutton4,'value')%hold button
        if checkhold==0
            'Hold is off so clear'
            cla(handles.axes1);
            hold(handles.axes1,'on')
        else
            hold(handles.axes1,'on');
        end
        
        axis tight;
   
        size([x;y;z])
        
            
        delaunaytri(x',y',z','parent',handles.axes1,'HandleVisibility','on');
    
        'lines';
        lx=[X(1);X(1)+((max(max(x))-min(min(x)))+.001)*1];
        ly=[y(1);Y(1)+((max(max(y))-min(min(y)))+.001)*1];
        lz=[Z(1);Z(1)+((max(max(Z))-min(min(Z))) +.001)*.5];
        line(lx,ly,lz,'LineWidth',4,'parent',handles.axes1);
        
        
        text(lx(2),ly(2),lz(2),plotName,'parent',handles.axes1,'HorizontalAlignment','center',...
            'BackgroundColor',[.7 .9 .7]);
        
        
        XNames=get(handles.popupmenuX,'string');
        YNames=get(handles.popupmenuY,'string');
        ZNames=get(handles.popupmenuZ,'string');
        xlabel(XNames(xColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        ylabel(YNames(yColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        zlabel(ZNames(zColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        title(handles.axes1,fileName,'FontSize',24,'Color','black','background','white','EdgeColor','black')
        axis auto
        
    otherwise
end




% than perform this task
% --- Executes during object creation, after setting all properties.
function popupmenuPlot_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenuPlot (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function setPopupmenuString(hObject, eventdata, handles)

fileName=handles.fileName;
[numbers,colNames]=xlsread(fileName);

set(hObject,'string',colNames);
guidata(hObject, handles);


function [xx, yy,AA,ogXColSize,ogYColSize,a]= readExcelColumns(fileName,xColNum,yColNum)



%%[typ, desc] = xlsfinfo(fileName)
desc = 1;
AA=size(desc)

fakea=xlsread(fileName);
[far,fac]=size(fakea);
xx=zeros(far,AA(2));
yy=xx;

   i=1; 
    a=xlsread(fileName);
    
    xx(:,i)=a(:,xColNum);
    yy(:,i)=a(:,yColNum);
    

[ogXColSize ogXRowSize]=size(xx);
[ogYColSize ogYRowSize]=size(yy);



% --- Executes on button press in radiobutton4.
function radiobutton4_Callback(hObject, eventdata, handles)%Hold Button
% hObject    handle to radiobutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton4
% hObject    handle to radiobutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton3
guidata(hObject,handles)
if (get(hObject,'Value') == 1)
    % Radio button is selected-take approriate action
    'on'
    hold(handles.axes1,'on')
    
    
    
else
    % Radio button is not selected-take approriate action
    hold(handles.axes1,'off')
    
end


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)%Import Z Matrix
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)





handles.fileNameZimport=uigetfile('*.dat');
guidata(hObject,handles)



fileNameZimport = handles.fileNameZimport;

Z= dlmread(fileNameZimport);


xColNum  = get(handles.popupmenuX,'value');
yColNum  = get(handles.popupmenuY,'value');
zColNum = get(handles.popupmenuZ,'value');

fileName = handles.fileName;


XNames=get(handles.popupmenuX,'string');
YNames=get(handles.popupmenuY,'string');
ZNames=get(handles.popupmenuZ,'string');


fileName = handles.fileName;

AA=char(XNames(xColNum));
BB=char(YNames(yColNum));
CC=char(ZNames(zColNum));
DD=char(fileName);

sAA=size(AA);
sBB=size(BB);
sCC=size(CC);
sDD=size(DD);
if sAA(2)>5
    AA=AA(1:5);
end

if sBB(2)>5
    BB=BB(1:5);
end

if sCC(2)>5
    CC=CC(1:5);
end

if sDD(2)>5
    DD=DD(1:10);
end

plotName=strcat(DD,' _ ',AA,' vs.',BB,' vs. ',CC)


lx=[0;10];
ly=[0;10];
lz=[0;10];

line(lx,ly,lz,'LineWidth',4,'parent',handles.axes1);

text(lx(2),ly(2),lz(2),plotName,'parent',handles.axes1,'HorizontalAlignment','center',...
    'BackgroundColor',[.7 .9 .7]);

  xlabel(XNames(xColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        ylabel(YNames(yColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');
        zlabel(ZNames(zColNum),'FontSize',16,'Color','black','background','white','EdgeColor','black');

surf(handles.axes1,Z)
guidata(hObject,handles)

A=get(handles.radiobutton4,'value')

if A==0
    handles.buttonCounter =1;
    set(handles.text7,'String',num2str(handles.buttonCounter) );
    guidata(hObject, handles); %without this line, the handles structure would not update,
    %and the counter would not increment
    
end

if A==1
    
    handles.buttonCounter = handles.buttonCounter + 1;
    set(handles.text7,'String',num2str(handles.buttonCounter) );
    guidata(hObject, handles); %without this line, the handles structure would not update,
    %and the counter would not increment
end



% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)%Export Z matrix
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)



xColNum  = get(handles.popupmenuX,'value');
yColNum  = get(handles.popupmenuY,'value');
zColNum = get(handles.popupmenuZ,'value');

XNames=get(handles.popupmenuX,'string');
YNames=get(handles.popupmenuY,'string');
ZNames=get(handles.popupmenuZ,'string');

fileName = handles.fileName;

[x, y,AA,ogXColSize,ogYColSize,a]= readExcelColumns(fileName,xColNum,yColNum);
[x, z,AA,ogXColSize,ogYColSize,a]= readExcelColumns(fileName,xColNum,zColNum);


[xr,xc]=size(x);
bigx=zeros(xr*xc,1);
bigy=bigx;
bigz=bigx;

for i=1:xc
    for j=1:xr
        bigx((i-1)*10+j,1)=x(j,i);
        bigy((i-1)*10+j,1)=y(j,i);
        bigz((i-1)*10+j,1)=z(j,i);
        
    end
end


data=[bigx'; bigy'];

a0 = [0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.0]; % Starting guess

options=optimset('MaxFunEvals',100000,'TolFun',1e-10,'MaxIter',10000);

bigz'
[a, resnorm] = lsqcurvefit(@myfun, a0, data, bigz',[],[],options);


deltaX=(max(x)-min(x))/100;%was .1 when ganesh did it

deltaY=(max(y)-min(y))/100;%was .1 when ganesh did it

gX=min(x):deltaX:max(x);
gY=min(y):deltaY:max(y);

[X,Y]=meshgrid(gX,gY);



Z = a(1)*X+ a(2)*X.^2 + a(3)*X.^3+a(4)*Y + a(5)*Y.^2 + a(6)*Y.^3+a(7)*X.*Y+a(8);


%ExcelFileName=strcat('x=',char(XNames(xColNum)),' y=',char(YNames(yColNum)),' z=',char(ZNames(zColNum)),' map')
AA=char(XNames(xColNum));
BB=char(YNames(yColNum));
CC=char(ZNames(zColNum));
DD=char(fileName);

sAA=size(AA);
sBB=size(BB);
sCC=size(CC);
sDD=size(DD);

for i=1:sAA(2)
    if isvarname(AA(i))==0
        AA(i)='_';
        
    end
    
end

for i=1:sBB(2)
    if isvarname(BB(i))==0
        BB(i)='_';
        
    end
    
end

for i=1:sCC(2)
    if isvarname(CC(i))==0
        CC(i)='_';
        
    end
    
end

for i=1:sDD(2)
    if isvarname(DD(i))==0
        DD(i)='_';
        
    end
    
end


if sAA(2)>5
    AA=AA(1:5);
end

if sBB(2)>5
    BB=BB(1:5);
end

if sCC(2)>5
    CC=CC(1:5);
end

if sDD(2)>10
    DD=DD(1:10);
end

ExcelFileName=strcat(DD,'_',AA,'VS',BB,'VS',CC)

ExcelFileName=genvarname(ExcelFileName);

ExcelFileName=strcat(ExcelFileName,'.dat')
dlmwrite(char(ExcelFileName), Z)


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)%Export Pictures
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
I = getframe(gcf);


xColNum  = get(handles.popupmenuX,'value');
yColNum  = get(handles.popupmenuY,'value');
zColNum = get(handles.popupmenuZ,'value');


XNames=get(handles.popupmenuX,'string');
YNames=get(handles.popupmenuY,'string');
ZNames=get(handles.popupmenuZ,'string');


fileName = handles.fileName;

AA=char(XNames(xColNum));
BB=char(YNames(yColNum));
CC=char(ZNames(zColNum));
DD=char(fileName);

sAA=size(AA);
sBB=size(BB);
sCC=size(CC);
sDD=size(DD);

for i=1:sAA(2)
    if isvarname(AA(i))==0
        AA(i)='_';
        
    end
    
end

for i=1:sBB(2)
    if isvarname(BB(i))==0
        BB(i)='_';
        
    end
    
end

for i=1:sCC(2)
    if isvarname(CC(i))==0
        CC(i)='_';
        
    end
    
end

for i=1:sDD(2)
    if isvarname(DD(i))==0
        DD(i)='_';
        
    end
    
end


if sAA(2)>5
    AA=AA(1:5);
end

if sBB(2)>5
    BB=BB(1:5);
end

if sCC(2)>5
    CC=CC(1:5);
end

if sDD(2)>10
    DD=DD(1:10);
end

ExcelFileName=strcat(DD,'_',AA,'VS',BB,'VS',CC)

ExcelFileName=genvarname(ExcelFileName);

ExcelFileName=strcat(ExcelFileName,'.png')



imwrite(I.cdata, char(ExcelFileName),'png');


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)%Diff in 2 surfaces
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

A=handles.buttonCounter;

if A==2
    'plot here';
    cla(handles.axes1)
    
    % load('MyColormaps','mycmap')
    %top=(size(mycmap)-size(handles.Zretained2))/2
    %mycmap2=mycmap(1,:)
    %set(handles.axes1,'Colormap',mycmap)
    
    %set(handles.axes1,'CLimMode','auto')
    %,'CData',mycmap
    combined=surf(handles.Xretained1,handles.Yretained1,abs(handles.Zretained1-handles.Zretained2),'parent',handles.axes1);
    %    surf(handles.Xretained1,handles.Yretained1,handles.Zretained1.*0,'parent',handles.axes1,'r')
    
    cmap = colormap;
    
    
    [cc,dd]=size(cmap)
    first=[0         0    0.5625]
    last=[  0.5625 0 0]
    
    
    
    cmap(1,:)=last
    
    
    
    for i=2:cc
        cmap(i,:)=first
    end
    
    
    
    
    cmapnew=cmap
    colormap(cmap)
    
    %
    %     [aa,bb]=size(absZ)
    %    bsZ=abs(handles.Zretained1-handles.Zretained2);
    %    Zmin=min(min(absZ));
    %    Zmax=max(max(absZ));
    %
    %    for i=1:aa
    %        for j=1:bb
    %            if absZ(i,j)<=.5*(Zmin-Zmax)
    %                absZ(i,j)=1;
    %            else
    %                absZ(i,j)=.5;
    %            end
    %        end
    %    end
    %   alpha(absZ)
    %
    
    
else
    helpdlg('Please press button only when 2 surfaces are present');
end


% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)%Excel Title
% hObject    handle to pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
HelpTitle='Excel Help';
A1='Correctly Formatted excel files should have the following:';
A2='**Worksheets labeled at "Sheet1, Sheet2", etc.';
A3='**No cells should be merged.';
A4='**Excel ?95 format files work for sure.'
A5='**Each column should have a title in the first row and nothing but numbers below it.'
A6='**Characters should all be black.'
A7='**Blank data is common, in which case the cell should be left blank.'
A8='**If importing data on several sheets, each sheet should have the same number of elements to create viable matrix.'
A9='   -> Copying and pasting the last row for each sheet with less than the maximum number of rows in the Excel file can artificially do this.'



dialogue=strvcat(1,A1,A2,A3,A4,A5,A6,A7,A8,A9);
helpdlg(dialogue,HelpTitle);



function TolEdit_Callback(hObject, eventdata, handles)
% hObject    handle to TolEdit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of TolEdit as text
%        str2double(get(hObject,'String')) returns contents of TolEdit as a double
Tol=str2double(get(hObject,'String'));


% --- Executes during object creation, after setting all properties.
function TolEdit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to TolEdit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in radiobutton4.



% --- Executes on button press in checkbox3.
function checkbox3_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox3
Tol=get(handles.TolEdit,'value');

if Tol>1 || Tol<0 ||isnan(Tol)==1
    'dialogue'
    helpdlg('Value must be between 0 and 1','Tolerance Input Error');
    
else
    
    popupmenuPlot_Callback(hObject, eventdata, handles)
    
end

Contact us