How to find index of non-alternate matrix elements?
Show older comments
i have two matrices say,
clear; close all; clc;
A = [1 3 5 7 9 11 13]; % nx1 matrix
B = [2 4 6 8 10 12 14]; % mx1 matrix
C = [A,B];
C = C';
D = sort(C);
This gives me matrix 'D' with elements from both A and B alternately.
However, if my matrix changes a bit in between like
clear; close all; clc;
A = [1 3 7 9 11 13]; % nx1 matrix
B = [2 4 6 8 10 12 14]; % mx1 matrix
C = [A,B];
C = C';
D = sort(C);
Then my matrix D with not have continuous alternate values from both matrix.
How can i find the index of this discontinuity, each time when the value repeats?
The final matrix D should have continuously increasing values.
3 Comments
madhan ravi
on 25 Dec 2018
Edited: madhan ravi
on 25 Dec 2018
upload your desired output , incase if you didn‘t notice both your codes are the same
Walter Roberson
on 25 Dec 2018
Looks to me as if you should be considering
D = reshape([A;B], 1, []);
Stephen23
on 25 Dec 2018
@Walter Roberson: except in the second example A and B have different numbers of elements.
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!