Determining which came first, Min or Max and then subtracting

조회 수: 1 (최근 30일)
m j
m j 2016년 9월 13일
댓글: Jan 2017년 3월 1일
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);

답변 (2개)

John BG
John BG 2016년 9월 13일
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
John BG
John BG 2017년 3월 1일
if you doubt it means you haven't checked.
If you had checked you would see it works, do you wanna bet?
Jan
Jan 2017년 3월 1일
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.

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


Jan
Jan 2017년 2월 26일
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
Image Analyst
Image Analyst 2017년 2월 26일
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.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by