Determining which came first, Min or Max and then subtracting

4 ビュー (過去 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 Center および File ExchangeParallel Computing Fundamentals についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by