logic in matlab to filter result

조회 수: 8 (최근 30일)
ali hassan
ali hassan 2020년 11월 18일
편집: Image Analyst 2020년 11월 19일
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

채택된 답변

Image Analyst
Image Analyst 2020년 11월 18일
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
Image Analyst
Image Analyst 2020년 11월 18일
편집: Image Analyst 2020년 11월 19일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by