picking maximum difference across entries of row vectors, Part 2
9 次查看(过去 30 天)
显示 更早的评论
I would like to generalize the previous question ( https://www.mathworks.com/matlabcentral/answers/404240-picking-maximum-difference-across-entries-of-row-vectors )
Now A is a table with the first column has the date data. (not a variale)
Please advise how to proceed in this general case.
for each row, take a difference between every possible pair of two elements in the row and returns the maximum difference
In a simpler case where A is a matrix, if A= [1 3 6 7 10], then B=[9].
回答(2 个)
Matt J
2018-6-6
result = max(A{:,2:end},[],2)-min(A{:,2:end},[],2)
5 个评论
Matt J
2021-4-30
编辑:Matt J
2021-4-30
Well, if A is a matrix then max(A,[],2) will give the row-wise maximum of A and similarly for min(). So, if your goal is to obtain a row vector containing the differences between the row-wise max and min of a matrix A, then it would simply be,
p = ( max(A,[],2)-min(A,[],2) ).'
You don't need the indexing A(1:end,:) when A is a matrix. My original answer was intended for when A is a table.
Aakash Deep
2018-6-6
Hello,
In order to find out the maximum difference between two elements in a row vector, you can first sort it and then take the difference between the last and the first element.
vec = sort(A);
B = vec(end)-vec(1);
Hope this helps :)
3 个评论
另请参阅
类别
在 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!