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!