An assignment I have says...
"An n-by-n square logical matrix can be represented by a cell vector of n elements where the kth element corresponds to the kth row of the matrix. Each element of the cell vector is a row vector of positive integers in increasing order reperesenting the column indexes of the logical true values in the given row of the matrix. All other elements in the given row of the ligical matrix are false. Write a function that takes such a cell vector as its only input and returns the corresponding square logical matrix. For example, such a cell vector representation of a 100-by-100 logical matrix with the only true elements at indexes (10,20) and (10,75) would have only one non-empty element of the 100-element cell vector at index 10. that element is the vector [20 75]."
I understand the input is the "indices" (non-traditional since they just give the location within each row, instead of within the entire array) at which the function should output logical trues; however, I am having a difficult time figuring out how to actually index into the zeros array my function creates using these indices. Here's an example of what the function is supposed to do...
for n = 3 (also length(A))
function output = input(A)
A = {[1 3], [], [2]}
output =
1 0 1
0 0 0
0 1 0
***notice that the size of the matrix is a 3x3 because that was the length of input A.
Here's my attempt, although I'm rather new to MATLAB so there are likely many mistakes...
function answer = hw5_problem4(Q)
X = length(Q);
Z = zeros(X, X);
row = Q(1:end);
col = Q{1:end};
Z(row, col) = true;
answer = Z;
return
end
***notice I created a zeros matrix and then attempted to "update" the matrix by indexing into the matrix and changing all the falses in those locations to trues; however, the error message I keep recieving is...
Unable to use a value of type 'cell' as an index.
Error in hw5_problem4 (line 6)
Z(row, col) = true;
Since Q is a cell vector I though Q(1:end) would work but I guess it doesn't?
PLEASE HELP :)