picking maximum difference across entries of row vectors, Part 2

조회 수: 4 (최근 30일)
alpedhuez
alpedhuez 2018년 6월 6일
댓글: Süleyman burak Dogaroglu 2021년 4월 30일
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
Matt J 2018년 6월 6일
result = max(A{:,2:end},[],2)-min(A{:,2:end},[],2)
  댓글 수: 5
Matt J
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.
Süleyman burak Dogaroglu
Süleyman burak Dogaroglu 2021년 4월 30일
thanks so much. now it is clear to me.

댓글을 달려면 로그인하십시오.


Aakash Deep
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
Stephen23
Stephen23 2018년 6월 6일
편집: Stephen23 2018년 6월 6일
@alpedhuez: If you post a follow-up question please put a link to the original question. It helps us to keep track of what information or answers you have already been given, and what extra clarifications or data you have given us about the question.
alpedhuez
alpedhuez 2018년 6월 6일
Thank you for letting me know.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by