Why does inequality give different values even though its evaluating the exact same matrix ??
조회 수: 3 (최근 30일)
이전 댓글 표시
Howcome these two yield different values ??
load td
version1 = sort(td(td(:,5) < 11.29))
t = (td(:,5));
version2 = sort(t(t < 11.29))
version1 - version2
댓글 수: 0
채택된 답변
Walter Roberson
2021년 12월 11일
sort(td(td(:,5) < 11.29))
td is a 2D array with multiple columns. You construct a mask from one of the columns, and you use it to index the entire td array -- which by linear indexing is going to effectively have it operate on the first column.
t = (td(:,5));
sort(t(t < 11.29))
but here you extract the column and your linear indexing is against the extracted version that only contains the one column.
댓글 수: 2
Walter Roberson
2021년 12월 11일
version3 = sort(td(td(:,5) < 11.29, 5))
is a possible way. But your second version with a temporary variable works well and is easier to read.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!