Suppose I replace NaN by -infty. Then the problem would be about taking the difference between max and min among nonzero elements for each row.
picking maximum difference across entries of row vectors, Part 3
1 回表示 (過去 30 日間)
古いコメントを表示
alpedhuez
2018 年 6 月 6 日
回答済み: Kaushik Lakshminarasimhan
2018 年 6 月 7 日
This is a follow-up with a previous question. https://www.mathworks.com/matlabcentral/answers/404403-picking-maximum-difference-across-entries-of-row-vectors-part-2
The question is
for each row, take a difference between every possible pair of two elements in the row and returns the maximum difference
Now A can have missing values. For example, A =[ NaN NaN 3 9 4]. In this case the previous solution
vec = sort(A);
B = vec(end)-vec(1);
does not return a correct answer 6. Please advise.
2 件のコメント
採用された回答
Kaushik Lakshminarasimhan
2018 年 6 月 7 日
A = [NaN NaN 3 9 4 ; 1 100 NaN 34 12];
maxdiffs = max(sort(A,2),[],2) - min(sort(A,2),[],2);
0 件のコメント
その他の回答 (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!