필터 지우기
필터 지우기

Coordinates of a vector

조회 수: 10 (최근 30일)
Deep P
Deep P 2017년 11월 27일
댓글: Star Strider 2017년 11월 27일
Hello,
I am trying to find the coordinates of all elements of a vector, with reference to a image. However, in the for loop, only the last element's coordinates are shown. Please help how to increment the coordinates and keep all their values using subscripts for the coordinates.
for ex; if my vector is [1 2 3 4], I Want to find coordinates of all these elements with reference to another image , say 'I'. I used find.
here is my code, for i=1:4 [x,y]=find(I=vector(i)); end. But in the command window, only the fourth element's coordinates are shown and I wanted all the element's coordinates. Please help. Thank you

답변 (1개)

Star Strider
Star Strider 2017년 11월 27일
Try this:
for i=1:4
[x{i},y{i}]=find(I==vector(i));
end
  댓글 수: 2
Deep P
Deep P 2017년 11월 27일
Thanks for your response, since resultant is a cell array, how do i get each element which is a vector and perform my operations?
Star Strider
Star Strider 2017년 11월 27일
You have to extract each to a (Nx2) matrix:
M = cell2mat([x{1} y{1}]);
and so for the rest. If the all have the same number of rows, then you can concatenate them horizontally and use cell2mat on the concatenated cell arrays.
See Access Data in Cell Array (link) for an extended discussion.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by