フィルターのクリア

Shifting values in a matrix, Alignment of two matrices

8 ビュー (過去 30 日間)
mattyice
mattyice 2015 年 12 月 22 日
コメント済み: mattyice 2015 年 12 月 22 日
I want to align the values of two matrices so that the corresponding values in one column will align the other columns. For example
A=
1 2.5
2 5.4
3 4.3
4 3.3
5 5.4
6 2.5
B=
6 3.3
7 5.4
5 2.5
3 2.5
5 5.4
9 4.3
I want to manipulate matrix B so that it's second column aligns with A so I can get a third matrix
C =
1 2.5 3 2.5
2 5.4 5 5.4
3 4.3 9 4.3
4 3.3 6 3.3
5 5.4 7 5.4
6 2.5 5 2.5
Then separate the 1st and 3rd columns
D=
1 3
2 5
3 9
4 6
5 7
6 5

回答 (3 件)

jgg
jgg 2015 年 12 月 22 日
編集済み: jgg 2015 年 12 月 22 日
I think you can do it this way:
[~,ind] = ismember(B(:,2),A(:,2))
C = [A,B(ind)];
D = C(:,[1,3]);
I'm not sure how well this will perform if they do not perfectly align, though.
  1 件のコメント
mattyice
mattyice 2015 年 12 月 22 日
This gives me this for D
D=
1 3
2 7
3 6
4 6
5 7
6 5
Which is incorrect

サインインしてコメントする。


Andrei Bobrov
Andrei Bobrov 2015 年 12 月 22 日
[~,ib] = sortrows(B,[2 1]);
[~,ia] = sortrows(A,[2 1]);
[~,ia2] = sort(ia);
D = [A(:,1),B(ib(ia2),1)];

Image Analyst
Image Analyst 2015 年 12 月 22 日
Shifting (translating) and sorting are two different things. Which do you want?
For shifting you'd use "register" the array with imregister() or do normalized cross correlation with normxcorr2() (I have a demo if you want it).
For sorting you'd simply use sort() - it's so simple that we hardly need to show you.
  2 件のコメント
mattyice
mattyice 2015 年 12 月 22 日
Could I see that demo? I want to basically shift the bottom 3 rows of matrix B to the top of the matrix
Image Analyst
Image Analyst 2015 年 12 月 22 日
Normxcorr2() is used to find a template in another image. The demo is attached.
If you want to shift the image a little bit, it sounds like imregister() is exactly what you want. There are demos for it in the help. I think there are some other functions that are better for very large shifts. Search this forum for imregister or registration or Alex Taylor (the Mathworks developer who wrote them).

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by