필터 지우기
필터 지우기

How to create an index based on highest number in data

조회 수: 1 (최근 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

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by