How to create an index based on highest number in data

1 次查看(过去 30 天)
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

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by