picking maximum difference across entries of row vectors, Part 2
Mostrar comentarios más antiguos
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].
1 comentario
Stephen23
el 6 de Jun. de 2018
Respuestas (2)
Matt J
el 6 de Jun. de 2018
result = max(A{:,2:end},[],2)-min(A{:,2:end},[],2)
5 comentarios
Süleyman burak Dogaroglu
el 30 de Abr. de 2021
Editada: Süleyman burak Dogaroglu
el 30 de Abr. de 2021
Hii
your answer help me soo much but i have to change it a little bit. such as;
p=[max(A(1:end,:),[],2)-min(A(1:end,:),[],2)];
result=p';
and i think you guessed what i need to find. so as a result could you please explain me that how these
max(A(1:end,:),[],2) and min(A(1:end,:) definitions work.
Matt J
el 30 de Abr. de 2021
Explain beyond what is in the documentation for max()?
Süleyman burak Dogaroglu
el 30 de Abr. de 2021
:) I m sorry i just want to understant the sequance behind the equation. also what's the meaning of ':' character and i replace it at the end of the inside bracet but the result didn't change. why could it be?
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
el 30 de Abr. de 2021
thanks so much. now it is clear to me.
Aakash Deep
el 6 de Jun. de 2018
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 comentarios
alpedhuez
el 6 de Jun. de 2018
@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
el 6 de Jun. de 2018
Categorías
Más información sobre Dates and Time en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!