Azzera filtri
Azzera filtri

How to create an index based on highest number in data

1 visualizzazione (ultimi 30 giorni)
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?

Risposta accettata

Image Analyst
Image Analyst il 3 Set 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.

Più risposte (1)

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

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by