How do i do this?
조회 수: 1 (최근 30일)
이전 댓글 표시
- Check if SelectLogicalN( [-2, 3, 6; 5, 78, 44; 9, -3, -53;], [1, 0, 0; 0, 0, 1; 1, 1, 1;], 4) returns [-2; 9; -3; 44;].
- Check if SelectLogicalN( [-9, 3, 6; 2, 67, 1; 5, -4, -17; ], [ 0, 0, 0; 0, 1, 1; 1, 1, 0; ], 3) returns [5; 67; -4].
- Check if SelectLogicalN( [-1, 4, 7; -2, 5, 8; -3, 6, 9], [1, 1, 0; 1, 1, 0; 1, 1, 0;], 5) returns [-1; -2; -3; 4; 5].
댓글 수: 3
Rik
2020년 11월 16일
Probably by indexing the result. What is it exactly you want to do? What is the input and what is the output?
답변 (1개)
Rik
2020년 11월 16일
Assuming that the comments in your screenshot are from the instructor guiding you through the writing of the function: I disagree with the proposed structure. What should happen if a user decides to call SelectLogicalN(rand(10,3),false(10,3),100)? The proposed structure will lead to an error, instead of simply returning a smaller vector (which is what I personally would prefer). I think this function should either return a smaller array, or trigger a custom error, telling the user what went wrong.
As for helping you solve this homework question:
I think it is better to use the logical input to determine a vector of indices. There is a built-in function that will do exactly that for you. You can even pass in the maximum number of indices. Can you figure out which function I'm referring to? Which functions do you know that take a logical input and will return the positions of true elements?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!