%%Vector Conditional Execution and String Operations
% Recall that boolean relational operators work on vectors
% Didn't mention how boolean vectors work for conditional execution (if,
% while, etc)

% When used for conditional execution, a boolean vector is considering true
% only when all of the entries are 1's (and it's only false when all of the
% entries are 0's)

%Basic example:
vec1 = [2, 5, 7, 9];
vec2 = [1, 8, 7, 3];
v1_eq_v2 = vec1 == vec2;
v1_neq_v2 = vec1 ~= vec2;
disp(v1_eq_v2)
disp(v1_neq_v2)

if(v1_eq_v2)
  disp('hello')
elseif(v1_neq_v2)
  disp('hello')
end

v1_geq_1 = vec1 >= 1;
if(v1_geq_1)
  disp('hello')
end

%String example:
%choice = input('Enter yes, no, or maybe: ', 's');
choice = 'Yes';
if choice == 'yes'
  disp('you chose "yes"')
end

%String is a vector of characters
%Could handle vector dimension issue with short-curcuiting
%if length(choice) == 3 && choice == 'yes'
%  disp('you chose "yes"')
%end
%Problem: short-curcuiting only works with scalar input
%We need a few helper functions, convert a vector of booleans into a single boolean:
%all(vec) - true if all values in vec are true
%any(vec) - true if any values in vec are true
choice = 'yes';
if length(choice) == 3 && all(choice == 'yes')
  disp('you chose "yes"')
end

%%String Operations
%Better way to do this: Use built-in MATLAB functions
%strcmp(string1,string2) - Compare 2 strings and return 1 if they are
%equal, return 0 otherwise
%strcmpi(string1,string2) - Compare 2 strings ignoring case

%Better string example:
choice = input('Enter yes, no, or maybe: ', 's');

if strcmpi(choice,'yes')
  disp('you chose "yes"')
end

%Other useful string functions:
%lower(str) - changes the string to lower case
%upper(str) - changes the string to upper case

