I don't understand this question, does someone else?
Afficher commentaires plus anciens
The question is:

Can someone please explain it via an illustrative example?
Hands off if you happen across this question and decide its not up to your personal standards. I need some help, and the class is on-line and closed.
2 commentaires
DJ V
le 13 Déc 2016
Matthew Murphy
le 14 Déc 2016
Please accept the answer to this question that has helped you the most.
Réponse acceptée
Plus de réponses (3)
Guillaume
le 13 Déc 2016
It's very clear to me. Example input:
n = 5;
C = {[1 3 4]; [2 5]; []; 4; 1:5};
Desired output:
tf = logical([1 0 1 1 0 .... true value at index 1, 3, and 4
0 1 0 0 1 .... true value at index 2 and 5
0 0 0 0 0 .... false everywhere
0 0 0 1 0 .... true value at index 4
1 1 1 1 1]) % true value at all indices
Matthew Murphy
le 13 Déc 2016
So I'm going to work through this stream-of-consciousness, so no guarantees. Let's say the square matrix is a 5x5. Then, the cell vector is a 5x1 array with each cell as a 1x5 double array.
Now, let's say that original 5x5 had "true" values in the end elements of each row; indices 1 and 5 of each row are true. Then, our cell array would have cells that look like this:
(The last element may be a 2 or a 5 - slightly unsure of the wording in the question, so I'll address both cases.)
row1 = [1 false false false 5];
row2 = [1 false false false 2];
Since you are making a square matrix, you can initialize an all-false matrix based on the size of the input cell vector. Given that vector, we would want to expand each cell into the double array and go by cases then.
Case 1 (row1): In this case, a non-false value corresponds to a true value in the column given by the value in that place.
Case 2 (row2): In this case, a non-false value corresponds to a true value in the column given by the index of the value in that place.
So all in all, instantiate new matrix, unpack cell vector, loop through created arrays, place true values in the positions indicated by the cases.
You may have to modify slightly based on the dimension of the input cell vector (column or row vector).
DJ V
le 14 Déc 2016
1 commentaire
Guillaume
le 14 Déc 2016
Please, don't ask questions in an answer. Make a new question
You can make your program a lot more readable (in my opinion) using the fact that
if something == true
%...
end
is the same
if something
%...
end
and
if something == false
%...
end
is the same as
if ~something
%...
end
I have no ideas why you're trying to store 0s and 1s when you're supposed to store the column indices of the true values.
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
