logic in matlab to filter result

7 次查看(过去 30 天)
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