Determining which came first, Min or Max and then subtracting

1 visualización (últimos 30 días)
m j
m j el 13 de Sept. de 2016
Comentada: Jan el 1 de Mzo. de 2017
My goal is to compare which came first, the max value or minimum value, I use bsxfun() to find which index came first(max or min). But now I want to subtract the max or min value from each other, depending on which one came first.
So say max came first, so max value came before min value in this column, Now subtract max value from min value givin we know where they are located bc of indexs.
But im having trouble using the boolean logic to generate this form using bsxfun(), any ideas?
So with this:
[max_value1 max_index1] = max(data1);
[max_value2 max_index2] = max(data2);
[min_value1 min_index1] = min(data1);
[min_value2 min_index2] = min(data2);
%%compare max/min indexs
comInput1 = bsxfun(@lt, max_index1, min_index1); %%if max index is before min, then = 1
comInput2 = bsxfun(@lt, max_index2, min_index2);

Respuestas (2)

John BG
John BG el 13 de Sept. de 2016
do you mean this?
data1=randi([-10 10],1,10)
[max_data1 max_index]=max(data1);[min_data1 min_index]=min(data1);
if max_index>=min_index d=max_data1-min_data1; end
if max_index<min_index d=min_data1-max_data1; end
  3 comentarios
John BG
John BG el 1 de Mzo. de 2017
if you doubt it means you haven't checked.
If you had checked you would see it works, do you wanna bet?
Jan
Jan el 1 de Mzo. de 2017
I have checked it. While the original question seems to concern matrices, your question handles vectors only. Therefore I disagree that this answer should be accepted.

Iniciar sesión para comentar.


Jan
Jan el 26 de Feb. de 2017
The appearence of bsxfun in the question might mean, that the input is an array, not a vector. Then:
data1 = rand(3, 4);
[max_value1, max_index1] = max(data1);
[min_value1, min_index1] = min(data1);
comInput1 = (max_index1 < min_index1);
result = (min_value1 - max_value1) .* (2 * comInput1 - 1);
  1 comentario
Image Analyst
Image Analyst el 26 de Feb. de 2017
Reading between the lines of the unclear, ambiguous question, I'm wondering if what "m h" actually wanted was to align the two signals. So that when they said "subtract", perhaps they actually meant "shift" (like circshift()), so that some part of one or both signals aligns with some other part of the signal.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by