logic in matlab to filter result

7 visualizaciones (últimos 30 días)
ali hassan
ali hassan el 18 de Nov. de 2020
Editada: Image Analyst el 19 de Nov. de 2020
HELLO everyone.
i have a little query,.plzz answer in brief for better understanding.
actually i am getting the following two solutions as mentioned in each column as x,y and z.now i want to only keep the column in which value of z(bottom value) is positive.
plzz correct the code and mention it in comments.
CODE:
idx = any(possibleSol < 0) | any(imag(possibleSol) ~=0);
possibleSol(:, idx) = [ ];
BEST REGARDS

Respuesta aceptada

Image Analyst
Image Analyst el 18 de Nov. de 2020
Try this
% Extract z from the last row of possibleSol.
z = possibleSol(3, :);
% Find out which columns have the last row (z) as positive.
goodColumns = z > 0;
% Extract only those columns where z > 0
possibleSol = possibleSol(:, goodColumns)
  3 comentarios
Image Analyst
Image Analyst el 18 de Nov. de 2020
Editada: Image Analyst el 19 de Nov. de 2020
You can read : as basically "all rows". And idx is just a bad name for the variable -- it should be called goodIndexes or something much more descriptive than idx. Don't you just hate it when people use confusing, cryptic variable names? Anyway idx is a logical vector that says, for each element, whether to extract that column or not. For example
m = m(:, [1,1,0,0,1]);
would say to take all rows of m, but only columns 1, 2, and 5 and put those 3 extracted columns back into m.
Conversely, if I said
m(:, [1,1,0,0,1]) = [];
it says to remove columns 1, 2, and 5 by setting them equal to "null", or "empty", which is indicated by the two square brackets with nothing inside. So after that matrix m would contain only columns 3 and 4.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by