%% Question 2a

% The code is determining if each element of vec is greater than 5.

result = vec > 5;


%% Question 2b

% The code is summing the values of all of the elements in A

result = sum(sum(A));


%% Question 2c

% There are many possible solutions, but they all start with:
[rows, cols] = size(A);
trA = zeros(cols, rows);

% Using nested loops:
for r = 1:rows
    for c = 1:cols
        trA(c, r) = A(r, c);
    end
end

% Using a single loop over the rows of A:
for r = 1:rows
    trA(:, r) = A(r, :);
end

% Using a single loop over the columns of A:
for c = 1:cols
    trA(c, :) = A(:, c);
end


%% Question 3a

[X, Y] = textread('data.txt', '%f %f', 'headerlines', 1);

%% Question 3b
hist(X, 20);
hold on
hist(Y, 20);

% Any value between 70 and 80 should work to separate the values;
% the X values should be less than 70 and the Y values should be
% greater than 80

%% Question 3c

% Using a loop:
n = length(X);
for i = 1:n
    x = X(i);
    y = Y(i);
    if x > 70
        X(i) = y;
        Y(i) = x;
    end
end

% Without a loop:
I = find(X > 70);
tmp = X(I);
X(I) = Y(I);
Y(I) = tmp;

%% Question 3d

boxplot([X Y], {'X', 'Y'});


%% Question 3e

mean(X)
std(X)

mean(Y)
std(Y)


%% Question 4a

x <= 0 | x >= 10


%% Question 4b

% Use a for loop if you know how many times the loop should iterate,
% and use a while loop otherwise.


%% Question 4c

% Yes, this means that there are no values less than the first quartile
% and no values greater than the third quartile. For example:

x = [1 1 1 2 3 4 4 4];
boxplot(x)


%% Question 4d

% 4 inputs
% 3 outputs
% The programmer has forgotten to assign a value to the output z




