nokizorque

Part B Q2

Aug 15th, 2018
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.56 KB | None | 0 0
  1. function Validity = input_requirements(v)
  2.     Validity = 1; % Assume it is valid until it isn't
  3.     % Check the size of the input matrix
  4.     [m, n] = size(v);
  5.     if (m ~= 1) || (n ~= 3)
  6.         Validity = 0; % Set it invalid
  7.         return % Exit the function, no more checks needed
  8.     end
  9.     % Iterate over the matrix to check for invalid values
  10.     for n = 1:length(v)
  11.         % Check if it isn't a 1 or a 0
  12.         if (v(n) ~= 0) && (v(n) ~= 1)
  13.             Validity = 0; % Set it to invalid
  14.             break % Exit the loop
  15.         end
  16.     end
  17. end
Advertisement
Add Comment
Please, Sign In to add comment