Filter löschen
Filter löschen

How to create an index based on highest number in data

1 Ansicht (letzte 30 Tage)
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?

Akzeptierte Antwort

Image Analyst
Image Analyst am 3 Sep. 2018
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.

Weitere Antworten (1)

KSSV
KSSV am 3 Sep. 2018
A = rand(10,1) ; % random data for demo
B = reshape(A,2,[])' ;
iwant = [B(:,1)>B(:,2) B(:,1)<B(:,2)]
  1 Kommentar
Edward Johnsen
Edward Johnsen am 3 Sep. 2018
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

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by