fixing discontinuity in a matrix by swapping data in some rows

1 view (last 30 days)
Is it possible to have an automated script (using diff, abs, imag, sign, gradient or whatever) and look at rows of data1 and rearrange it using sortrows to a get data2? You can look at the following scripts and see generated figures to better understand what needs to be done. Corrected rows in data2 can be either real or complex (cannot be both). Conjugate complex numbers always exist in two rows but the sign of imaginary part should remain unchanged in each row. Numbers can be small, large, positive or negative. Columns are correct and should not be shifted. Only rows in different columns must be shifted to get correct data. The following example shows wrong data locations in data1([2:3],4), data1([6:7],[3:5]) and data1([5:6],[1:3]).
data1=[...
-1.00 + 0.00i, -0.50 + 0.00i, 0.00 + 0.00i, 0.50 + 0.00i, 1.00 + 0.00i;...
0.10 + 1.00i, 0.00 + 1.50i, -0.05 + 2.00i, -0.10 - 3.00i, -0.20 + 5.00i;...
0.10 - 1.00i, 0.00 - 1.50i, -0.05 - 2.00i, -0.10 + 3.00i, -0.20 - 5.00i;...
2.00 + 0.00i, 3.00 + 0.00i, 4.00 + 0.00i, 5.00 + 0.00i, 6.00 + 0.00i;...
-1.00 - 1.20i, -2.00 - 1.75i, -3.00 - 2.40i, -4.00 + 3.43i, -5.00 + 5.07i;...
-1.00 + 1.20i, -2.00 + 1.75i, -3.00 + 0.00i, -2.00 + 0.00i, -1.00 + 0.00i;...
-5.00 + 0.00i, -4.00 + 0.00i, -3.00 - 2.40i, -4.00 - 3.43i, -5.00 - 5.07i;...
];
figure
hold on
for k=1:size(data1,1)
plot(real(data1(k,:)),imag(data1(k,:)))
end
data2=[...
-1.00 + 0.00i, -0.50 + 0.00i, 0.00 + 0.00i, 0.50 + 0.00i, 1.00 + 0.00i;...
0.10 + 1.00i, 0.00 + 1.50i, -0.05 + 2.00i, -0.10 + 3.00i, -0.20 + 5.00i;...
0.10 - 1.00i, 0.00 - 1.50i, -0.05 - 2.00i, -0.10 - 3.00i, -0.20 - 5.00i;...
2.00 + 0.00i, 3.00 + 0.00i, 4.00 + 0.00i, 5.00 + 0.00i, 6.00 + 0.00i;...
-1.00 + 1.20i, -2.00 + 1.75i, -3.00 + 2.40i, -4.00 + 3.43i, -5.00 + 5.07i;...
-1.00 - 1.20i, -2.00 - 1.75i, -3.00 - 2.40i, -4.00 - 3.43i, -5.00 - 5.07i;...
-5.00 + 0.00i, -4.00 + 0.00i, -3.00 + 0.00i, -2.00 + 0.00i, -1.00 + 0.00i;...
];
figure
hold on
for k=1:size(data2,1)
plot(real(data2(k,:)),imag(data2(k,:)))
end

Answers (0)

Categories

Find more on Matrices and Arrays 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!