Assigning the pixel location
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
med-sweng
il 23 Feb 2014
Risposto: Image Analyst
il 23 Feb 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 Commenti
Risposta accettata
Image Analyst
il 23 Feb 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!