Assigning the pixel location
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
med-sweng
am 23 Feb. 2014
Beantwortet: Image Analyst
am 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 Kommentare
Akzeptierte Antwort
Image Analyst
am 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!