Cell array addressing:
Suppose B = {'James Bond', [1 2;3 4;5 6]; pi, 1:6}. What are the value returned by each of the following statements?
B{1,1}(7:end)
B{1,2}(3,1)
sum(B{1,2}(3:end))
cos(B{2,1})
mean(B{2,2}(2:2:end))
Cell array addressing:
Let's execute the following statements within MATLAB:
A = [7 5 6];
[myOutput{1:2}]=sort(A);
plot(myOutput{:}, 'o-');
What is the value of myOutput?
What is the result of the plot command?
Using 'num2cell' for a matrix:
Suppose A = [1 2 3;4 5 6]. What are the value returned by the following statements?
num2cell(A)
num2cell(A, 1)
num2cell(A, 2)
Using 'num2cell' for a 3D array:
Suppose matrix A is obtained via the following statements:
A(:, :, 1) = [1 2 3; 4 5 6];
A(:, :, 2) = [1 0 0; 0 0 1];
What is the value of B{1} after executing each of the following statements?
B = num2cell(A)
B = num2cell(A, 1)
B = num2cell(A, 2)
B = num2cell(A, 3)
Using 'mat2cell' for a matrix:
What is the value of C{end} after executing the following statements?
X = [1 2 3 4; 5 6 7 8; 9 10 11 12]
C = mat2cell(X,[1 2],[1 3])
Using 'struct2cell':
Suppose that S is defined by the following statement:
S = struct('name',{'Tim','Annie'},'age', {8,5});
What is the value of C after executing each of the following statements?
C = struct2cell(S(1))
C = struct2cell(S)
C = struct2cell(S')
Using 'deal':
What is the value of C after executing the following statements?
S = struct('name',{'Tim','Annie'},'age', {8,5});
[C{1:length(S)}] = deal(S.name);
Using 'deal' for collecting info:
What is the major purpose of the following statements? (Or what is contained in dirs?)
dirInfo = dir(matlabroot);
n = length(dirInfo);
[fileAndDir{1:n}] = deal(dirInfo.name);
dirs = fileAndDir([dirInfo.isdir])