How do i do this?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
- 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 Kommentare
Rik
am 16 Nov. 2020
Probably by indexing the result. What is it exactly you want to do? What is the input and what is the output?
Antworten (1)
Rik
am 16 Nov. 2020
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 Kommentare
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!