logic in matlab to filter result

7 visualizzazioni (ultimi 30 giorni)
ali hassan
ali hassan il 18 Nov 2020
Modificato: Image Analyst il 19 Nov 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

Risposta accettata

Image Analyst
Image Analyst il 18 Nov 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 Commenti
Image Analyst
Image Analyst il 18 Nov 2020
Modificato: Image Analyst il 19 Nov 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by