Assigning the pixel location
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
med-sweng
le 23 Fév 2014
Réponse apportée : Image Analyst
le 23 Fév 2014
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 commentaires
Réponse acceptée
Image Analyst
le 23 Fév 2014
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!