help regarding indexing matrix in image processing

3 次查看(过去 30 天)
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]

采纳的回答

Michael Haderlein
Michael Haderlein 2015-3-31
编辑:Michael Haderlein 2015-3-31
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by