Compare segments of a vector
Ältere Kommentare anzeigen
Hello good day.
I have a problem, which I hope you can give me support or advice: I have the following column vector of 20 elements (the real one is 1000 elements): A=[6.9563; 6.9563; 6.9563; 6.9563; 6.9563; 7.4917; 5.8343; 5.3075; 5.8713; 7.1312; 11.2175; 11.2175; 11.2175; 11.2175; 11.2175; 10.4278; 10.9766; 11.2685; 9.4748; 11.3789] The question is how to compare (greater than>) the first 5 elements with the second 5 elements of vector A. 6.9563 6.9563 6.9563 6.9563 6.9563 Compare with 7.4917 5.8343 5.3075 5.8713 7.1312 and after third 5 elements with the fourth 5 elements of the vector A 11.2175 11.2175 11.2175 11.2175 11.2175 Compare with 10.4278 10.9766 11.2685 9.4748 11.3789 And so on automatically, if the vector A is 1000 elements
I hope you understand me and help me. Greetings.
5 Kommentare
David Fletcher
am 6 Mär. 2018
I'd probably extract every other 5 five elements from A into B compact A down and then just compare with A>B.
Jos (10584)
am 6 Mär. 2018
What should the output look like? Can you give a numeric example with integers (whole numbers) to make life easier.
Ricardo Gutierrez
am 6 Mär. 2018
Jos (10584)
am 6 Mär. 2018
I fail see the relationship between the values of B and the values of A ...
Ricardo Gutierrez
am 7 Mär. 2018
Akzeptierte Antwort
Weitere Antworten (3)
David Fletcher
am 6 Mär. 2018
Bearbeitet: David Fletcher
am 6 Mär. 2018
ind=repmat(logical([0 0 0 0 0 1 1 1 1 1]),1,100)
b=a(ind)
a(ind)=[]
c=a>b
Fangjun Jiang
am 6 Mär. 2018
This example should give you an idea
A=transpose(reshape(rand(20,1),5,[]))
B=diff(A)
C=B>0
C should tell you the relation
Jos (10584)
am 7 Mär. 2018
Bearbeitet: Jos (10584)
am 7 Mär. 2018
A = [2 2 2 2 2 3 6 3 4 5 1 1 1 1 1 2 3 4 5 6]
AA = reshape(A,5,[])
dA = diff(AA,[],2)
ix = all(dA>0)
ix = 2*find(ix(1:2:end))
B = reshape(AA(:,ix),1,[])
2 Kommentare
Ricardo Gutierrez
am 7 Mär. 2018
Jos (10584)
am 7 Mär. 2018
Oh, I subtracted a 1 from ix by mistake! Corrected
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!