I don't understand this question, does someone else?
이전 댓글 표시
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
DJ V
2016년 12월 13일
Matthew Murphy
2016년 12월 14일
Please accept the answer to this question that has helped you the most.
채택된 답변
추가 답변 (3개)
Guillaume
2016년 12월 13일
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
2016년 12월 13일
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
2016년 12월 14일
댓글 수: 1
Guillaume
2016년 12월 14일
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.
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
