help regarding indexing matrix in image processing

1 Ansicht (letzte 30 Tage)
SUJATA MOURYA
SUJATA MOURYA am 31 Mär. 2015
Bearbeitet: Image Analyst am 31 Mär. 2015
i am working on quincux matrix for image sampling. i want to make the alternate elements zero of rows of a given matrix such that for each odd row the row starts with zero and for each even rows the second starting element is zero.
example:- given matrix is
[1 2 3 4 5;
6 7 8 9 1;
1 3 6 7 4;
2 9 7 8 5;
5 6 7 8 3]
result required is:-
[0 2 0 4 0;
6 0 8 0 1;
0 3 0 7 0;
2 0 7 0 5;
0 6 0 8 0]

Akzeptierte Antwort

Michael Haderlein
Michael Haderlein am 31 Mär. 2015
Bearbeitet: Michael Haderlein am 31 Mär. 2015
I think there are dozens of possibilities, I just thought about this particular one:
if mod(size(m,1),2)==0
m=[m;nan(1,size(m,2))];
end
m(1:2:end)=0;
if isnan(m(end,2))
m=m(1:end-1,:);
end
Please note that there must not be NaNs in the matrix. If there are NaNs, this code must be little modified. Tell me in this case.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by