2 vectors compare it
Ältere Kommentare anzeigen
Hello, Ineed help with this question. I have 2 vectors to compare. Matrix below is a simplified vector with 2 columns that I want to compare. I want to move across the columns from column 1 to column 2 to column 1 continously till the end of the vector in an ascending order. If I move across , I record a value +ve, if I move within the same column, I record -ve. E.g
2 to 3 is +ve
3 to 4 is +ve
4 to 5 is +ve
5 to 7 is -ve( same column)
7 to 9 is -ve of -ve = +ve (same column movement)
9 to 10 is +ve
10 t0 12 is +ve
12 to 16 is +ve
16 to 17 is -ve
17 to18 is +ve
18 to 19 is +ve
19 to20 is +ve
4 Kommentare
Dyuman Joshi
am 9 Nov. 2022
You have skipped 12 to 15 and 15 to 16. Was that a mistake or intentional?
If it was intentional, what is the logic behind it?
Joshua Folorunso
am 9 Nov. 2022
The OP has modified this question multiple times, finally deciding that they will delete it entirely. Note to OP: this kind of behavior is not appreciated on this forum.
Backups of the main versions of this question:
Rena Berman
am 27 Dez. 2022
(Answers Dev) Restored edit
Akzeptierte Antwort
Weitere Antworten (2)
Bruno Luong
am 9 Nov. 2022
Bearbeitet: Bruno Luong
am 9 Nov. 2022
A=[2 3
4 5
10 7
15 9
16 12
17 18
19 20];
[As,is] = sort(A(:));
col = 1 + (is>size(A,1));
Vesign = 2*~~diff(col)-1;
Vesign = cumprod(Vesign);
Ves = string(Vesign);
Ves = repmat("+", size(Vesign));
Ves(Vesign<0) = "-";
S = As(1:end-1);
T = As(2:end);
col_S = col(1:end-1);
col_T = col(2:end);
T = table(S,T,col_S,col_T,Ves)
1 Kommentar
Joshua Folorunso
am 9 Nov. 2022
Joshua Folorunso
am 8 Dez. 2022
0 Stimmen
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!