필터 지우기
필터 지우기

How to pick random values in a vector

조회 수: 1 (최근 30일)
Navya Snigdha Thumma
Navya Snigdha Thumma 2015년 10월 3일
댓글: Navya Snigdha Thumma 2015년 10월 3일
How to pick randomly intensities with non zero values in an image. I want to pick only two intensities. My answer should be (x1,y1) and (x2,y2) which are row and column values of particular image. Please help. Thanks.

채택된 답변

Walter Roberson
Walter Roberson 2015년 10월 3일
idx = find(YourImage ~= 0);
randidx = idx(randperm(length(idx),2));
[x, y] = ind2sub(size(YourImage), randidx);
x1 = x(1); x2 = x(2); y1 = y(1); y2 = y(2);
Caution: when you are talking about images, x is the column number, not the row number. I left it in the order you specified, but if you try to use it to plot with you will see that what you asked for is not the way it works.
  댓글 수: 1
Navya Snigdha Thumma
Navya Snigdha Thumma 2015년 10월 3일
It worked. Thank you very much. And thanks for the caution. I will check the order while plotting.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by