필터 지우기
필터 지우기

How do i do this?

조회 수: 1 (최근 30일)
Anita Osoh
Anita Osoh 2020년 11월 16일
답변: Rik 2020년 11월 16일
  • 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
Anita Osoh
Anita Osoh 2020년 11월 16일
oh my question is how do i change an array size after indexing it?
Rik
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
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?

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by