logic in matlab to filter result
8 ビュー (過去 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
0 件のコメント
採用された回答
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
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 Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!