Why does inequality give different values even though its evaluating the exact same matrix ??
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
HabenG
le 11 Déc 2021
Commenté : Walter Roberson
le 11 Déc 2021
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 commentaires
Réponse acceptée
Walter Roberson
le 11 Déc 2021
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 commentaires
Walter Roberson
le 11 Déc 2021
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!