How to create an index based on highest number in data

2 ビュー (過去 30 日間)
Edward Johnsen
Edward Johnsen 2018 年 9 月 3 日
コメント済み: Edward Johnsen 2018 年 9 月 3 日
I have a set of data (in a 360 * 1 vector) where i need matlab to read the first 2 lines, then assign the highest number in the first two lines a 1, and the other a 0, this needs to go on for each pair along the entire set. Any one got any ideas?

採用された回答

Image Analyst
Image Analyst 2018 年 9 月 3 日
If you have the Image Processing Toolbox, you can use blockproc() to process a pair of elements before jumping to the next pair down until it's gone all the way down the vector.
A = rand(360,1) % Random data for demo
% Define the function that we will apply to each block.
% In this demo we will take the max value in the block
% and create an equal size block where all pixels have the max value.
maxFilterFunction = @(theBlockStructure) max(theBlockStructure.data(:)) * ones(size(theBlockStructure.data), class(theBlockStructure.data));
% Block process the vector to replace every element in the
% 2 element block by the max of the values in the block.
blockSize = [2 1];
blockVector = blockproc(A, blockSize, maxFilterFunction) % Find elements of maxima.
% Construct output matrix.
B = [A, blockVector == A]
You'll get something like this:
B =
0.640283956310627 0
0.934334009701608 1
0.204451403319075 0
0.2808222992592 1
0.482153166343332 0
0.569773626383138 1
0.522844388080927 1
0.235050800044239 0
0.971156620920272 1
0.182306414206202 0
etc.

その他の回答 (1 件)

KSSV
KSSV 2018 年 9 月 3 日
A = rand(10,1) ; % random data for demo
B = reshape(A,2,[])' ;
iwant = [B(:,1)>B(:,2) B(:,1)<B(:,2)]
  1 件のコメント
Edward Johnsen
Edward Johnsen 2018 年 9 月 3 日
Hey there KSSV, thank you for your help.
That is sort of what I want, but what I need is it to create another column next to the original number where the larger in the pair is a 1, and the smaller is a 0, so I need it to be a 360*2 array where i have the original data and then its index in the second column

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by