Can I sort Find function base on rows?
3 ビュー (過去 30 日間)
古いコメントを表示
Hello
I use find function to find location of a vector on my Image, It works, but I have location Order by column.I mean at firs I have location of pixels on column1 then column2,..... Can I change find function to have location of pixels on row1,row2,.....?
I'll appreciate your help.
3 件のコメント
Image Analyst
2014 年 3 月 4 日
編集済み: Image Analyst
2014 年 3 月 4 日
I agree - totally confusing. Posting the image would probably help, as well as reading this. And say what you want to do once you have this. Because I suspect you don't even need it. I think you might be able to do what you want to do just with a binary image - no need to get (x,y) coordinates of every single non-zero pixel. I mean, why? Why do you think you need that? There are some situations (e.g. edge linking) but I'd like to know your reason.
回答 (2 件)
Julian
2023 年 8 月 3 日
I couldn't find a nice solution in the documentation, so I assume the best way is instead of:
A = [1 0;
0 1;
1 0];
[row, col] = find(A);
% Results:
% row = [1; 3; 2]
% col = [1; 1; 2]
Transpose the matrix A and exchange the row and column:
[col, row] = find(A.');
% Results:
% row = [1; 2; 3]
% col = [1; 2; 1]
0 件のコメント
Walter Roberson
2014 年 3 月 4 日
[row, col] = find(.....);
cr = sortrows([col(:), row(:)];
r = cr(:,2);
c = cr(:,1);
now r(K), c(K) is a (row, column) pair and the pairs are ordered so that column varies more slowly. But it normally would anyhow. So perhaps what you want is
[row, col = find(.....);
rc = sortrows([row(:), col(:)]);
r = rc(:,1);
c = rc(:,2);
and that should be ordered with row varying more slowly, "going along rows", the opposite of what would normally happen.
6 件のコメント
Walter Roberson
2014 年 3 月 16 日
sort(A,2)
but you are now not working with vectors returned from find(), which are indices with row(K) corresponding to col(K) after the find and row(K), col(K) giving the location of what was found; you are now sorting by array content based upon the full array, which is a different task.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!