Assigning the pixel location
조회 수: 1 (최근 30일)
이전 댓글 표시
I have the following matrix:
a =
1 4
6 4
After that, I created a zero matrix `new` of the same size of `a`:
new =
0 0
0 0
I'm trying to do the following:
- assign the location `(2,1)` in `a` to the variable `p` - for that location in `new`, I want to give it the value `1`
For that, I did the following:
p=a(2,1);
new(p)=1;
But, I got the following:
In an assignment A(I) = B, a matrix A cannot be resized.
It seems that also `p=a(2,1);` assigns the value at that location and not the location itself.
How can I solve this issue?
Thanks.
댓글 수: 0
채택된 답변
Image Analyst
2014년 2월 23일
You can use a structure:
p.row = 2;
p.Col = 1;
Or you can use a single number if you use sub2ind to get a linear index
p = sub2ind(matrixSize, row, col);
Chances are that you don't really need to or want to do either of those. Chances are you can just make a logical array but I don't really know how to tell you the best way because I don't have the larger picture/context so all I can do it to tell you exactly what you asked, which like I said is probably not the best approach.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!