% Allow user to create their own cell array
% blah
% blah
% blah

clear all
close all
clc

% get array dimensions from user
row = input('How many rows would you like in your array? ');
col = input('How many columns would you like in your array? ');

% create the cell array
C = cell(row,col);

% iterate through the array an populate with user enetered values
for i=1:row
    for j=1:col
        fprintf('What would you like in position %d,%d?',i,j);
        C{i,j} = input(' ');
    end
end

% display the array to the user
C

disp('Let''s locate certain data types in your cell array.');

% initialize variables for the loops
yesNo = 'y';
counter = 0;

% continue to query user until they choose to quit
while yesNo == 'y'
    
    % get field type from user
    typeOf = input('What type of data would you like to locate? (vector,matrix,char,integer,numeric,cell) ','s');
    
    % confirm a valid entry
    if strcmp(typeOf,'vector') || strcmp(typeOf,'matrix') || strcmp(typeOf,'char') || strcmp(typeOf,'integer') || strcmp(typeOf,'numeric') || strcmp(typeOf,'cell')
        
        % loop through cell array and check for matching datatype
        % -- we could make a function call here but the instructions do not
        % require it
        for i=1:row
            for j=1:col
                if strcmp(typeOf,'vector') && isvector(C{i,j})

                    fprintf('You can find a %s in position %d,%d.\n',typeOf,i,j);
                    counter = counter + 1;

                elseif strcmp(typeOf,'matrix') && ismatrix(C{i,j})

                    fprintf('You can find a %s in position %d,%d.\n',typeOf,i,j);
                    counter = counter + 1;

                elseif strcmp(typeOf,'char') && ischar(C{i,j})

                    fprintf('You can find a %s in position %d,%d.\n',typeOf,i,j);
                    counter = counter + 1;

                elseif strcmp(typeOf,'integer') && isinteger(C{i,j})

                    fprintf('You can find a %s in position %d,%d.\n',typeOf,i,j);
                    counter = counter + 1;

                elseif strcmp(typeOf,'numeric') && isnumeric(C{i,j})

                    fprintf('You can find a %s in position %d,%d.\n',typeOf,i,j);
                    counter = counter + 1;

                elseif strcmp(typeOf,'cell') && iscell(C{i,j})

                    fprintf('You can find a %s in position %d,%d.\n',typeOf,i,j);
                    counter = counter + 1;

                end
            end
        end
        
        % check counter and if no matches found display message
        if counter == 0
           
            frpintf('Sorry, we couldn''t find a %s in the cell array.\n',typeOf);
            
        % if matches found, ask user if they want to see contents
        else
            
            display = input('Would you like to view the contents of these cells? (y,n) ','s');
    
            if strcmp(display,'y') && ~strcmp(display,'n')

                for i=1:row
                    for j=1:col
                        if strcmp(typeOf,'vector') && isvector(C{i,j})

                            C{i,j}

                        elseif strcmp(typeOf,'matrix') && ismatrix(C{i,j})

                            C{i,j}

                        elseif strcmp(typeOf,'char') && ischar(C{i,j})

                            C{i,j}

                        elseif strcmp(typeOf,'integer') && isinteger(C{i,j})

                            C{i,j}

                        elseif strcmp(typeOf,'numeric') && isnumeric(C{i,j})

                            C{i,j}

                        elseif strcmp(typeOf,'cell') && iscell(C{i,j})

                            C{i,j}

                        end
                    end
                end
                
            elseif ~strcmp(display,'y') && ~strcmp(display,'n')
                
                % user entered somthign other than y or n
                disp('Invalid value so we will assume you do not want to view contents.');

            end
            
        end
        
    else
        % user entry was invalid
        disp('You have entered an invalid datatype.');
      
    end
    
    % ask the user whether to continue anything other than 'y' exits the
    % loop
    yesNo = input('Would you like to find another type? (y,n) ','s');
    
    if ~strcmp(yesNo,'y') && ~strcmp(yesNo,'n')
       
        disp('You have entered an invalid value so we will now exit.');
        break;
        
    end

    
end

disp('Thanks for playing!');
