Borrar filtros
Borrar filtros

How do i do this?

1 visualización (últimos 30 días)
Anita Osoh
Anita Osoh el 16 de Nov. de 2020
Respondida: Rik el 16 de Nov. de 2020
  • 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 comentarios
Anita Osoh
Anita Osoh el 16 de Nov. de 2020
oh my question is how do i change an array size after indexing it?
Rik
Rik el 16 de Nov. de 2020
Probably by indexing the result. What is it exactly you want to do? What is the input and what is the output?

Iniciar sesión para comentar.

Respuestas (1)

Rik
Rik el 16 de Nov. de 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?

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by