% creating a logical vector in a program
% directly using the keywords true and false:
LogicVec = [ true true false true false]'
% This is seldom done this way.
% Logical vectors are usually the result of
% performing relational (and/or) logical operations.
% Recall that in input/output, MATLAB uses 
% 1 for true and 0 for false.
% That is why the output display for the above 
% logical vector contains elements of only 0 and 1.

% But if a vector (or matrix) is created by entering 
% 1 and 0 for it elements, it is NOT a logical
% vector. For example:
LogicVec2 = [ 1 1 0 1 0]'
% is simply a vector of double precision numbers.
% You can check that using "whos":
whos

% New topic: logicalIndexing
% See the script file: logicalIndexing.m

% New topic: strings

disp('A vector of characters: string');
Name = 'George Bush'
% index it just like a vector:
Name(2)
Name(2:8)
% Can make pattern matching (note case sensitive):
Name(2:5) == 'gatc'
Name(1:4) == 'gatc'
Name(1:4) == 'GTCA'     % only the G matches
whos

NAMES = ['Damon    '; 
         'Jeter    ';
         'Abreu    ';
         'Rodriguez';    % Arod's long name sets the number of columns
         'Giambi   ';
         'Nady     ';
         'Cano     ';
         'Ransom   ';
         'Betemit  ';
         'Molina   '];
[n,m]=size(NAMES)   % It is a 10 by 11 matrix of characters
NAMES(1,7)          % is a blank space
5*NAMES(1,7)        % uses the ASCII value (32) to do the arith. space

% Now topic: logical operation using & and |:
Ages = [ 36; 32; 29; 28; 35; 25; 24; 21; 23; 26],
[ (Ages<30) & (Ages > 24) Ages] % & means logical "and"
[ (Ages<30) | (Ages > 24) Ages] % mean logical "or"
[ (Ages<22) | (Ages > 24) Ages] % a better example
[ ~(Ages<30) | (Ages > 24) Ages] % ~ means logical negation

% Problem: to display their names together with
% their ages:
% Need to display the combine result as a single matrix.
% The problem is that they have different data typtes:
% the names are strings (array of characters) but
% the ages are numbers.
% The "disp" function displays a matrix, but we
% cannot combine 2 different data types into 1 matrix.
% Solution: use the "num2str" function to convert
% numbers to strings:
COMBINE_MTX = [ NAMES num2str(Ages)];
disp(COMBINE_MTX);
% But the numbers are merged together with the names!
% Need to put blank spaces separating the two.
% Create a colum of balnk spaces:
Blanks(1:length(Ages),1) = ' ';
disp('Insert these blanks between the names and the ages:');
COMBINE_MTX2 = [ NAMES Blanks num2str(Ages)];
disp(COMBINE_MTX2);
