MATLAB Answers

Cells and Cell vectors help?

2 views (last 30 days)
James Metz
James Metz on 3 Apr 2020
Commented: darova on 3 Apr 2020
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 am completely lost as to what the question is detailing/asking. Can somebody please explain what exactly this is saying?

  1 Comment

darova
darova on 3 Apr 2020
As i understood the task correctly: the matrix consists of false elements except some
Sounds like sparse matrix. Do you have more explanations? Maybe a picture?

Sign in to comment.

Accepted Answer

Matt J
Matt J on 3 Apr 2020
Edited: Matt J on 3 Apr 2020
So, as a smaller example, if n=4 and the input is this C={ [1 2] , [], [2 3 4], [] }, the output should be this,
A =
1 1 0 0
0 0 0 0
0 1 1 1
0 0 0 0
The contents of C{1} is [1,2] and this tells us that the first row has 1s in the first two elements and zeros elsewhere. Since C{3}=[2,3,4] the 3rd row has 1's in the second, third, and fourth elements and zeros elsewhere. Any row k for which C{k}=[] has only zeros in it.

  0 Comments

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!