How to use matlab function to fill or label the previous or next column cells with respect to certain column of of a matrix with a number (3)

As clear from figure, this is my M-matrix.
With respect to 2nd colum, in first colum, the 3rd row or 4th row i.e horizentally, i want to fill with 3 i.e. horizentally or diagonally.
similarly in 3rd column, i want to fill 3rd row or 4th rows same like above procedure.
% i want in each colum to have closing ie. startring 3 and then closing 3 i.e. the last one. Thanks for all coopeation. Warm regrads
question to ask.jpg

 채택된 답변

Try imdilate() -- it's a local max filter.
se = [0,0,0;1,1,1;1,1,1]
outputMatrix = imdilate(inputMatrix, se);

댓글 수: 6

@image analyist, if i want only introduce 3 diagonally, then how can we proceed. plz guide
Outputmatrix = [ 0 0 0
0 0 0
0 3 0
3 <-- 0 0 0 --> 3
0 0 0
3 3 3]
Hope you got my point, right. If i want to introduce 3 diagnonally only, ignorning the horizental 3s.then how should we proceed. Thanks for all cooperation. Regards
This will work:
% Create sample data.
m = zeros(11, 3);
% Set a few locations (7) to 3
randomLocations = randperm(numel(m), 7);
m(randomLocations) = 3
% Now we have our matrix and we can begin.
[rows, columns] = size(m);
mOut = m; % Initialize
for row = 2 : rows
% Check column 1
if m(row-1, 2) == 3
mOut(row, 1) = 3;
end
% Check column 2
if m(row-1, 1) == 3 || m(row-1, 3) == 3
mOut(row, 2) = 3;
end
% Check column 3
if m(row-1, 2) == 3
mOut(row, 3) = 3;
end
end
mOut % Print to command window
Image Analyst, thanks for giving idea. i want this coding as dynamic. i dont apply or metion colums 1 or 2 or 3. i want to handle it as general rows and columns.
plz help me how to apply it on a matrix.
i applied it but its giving me problem ie. out of bounds.
could you plz help how to sort it out.
% Create sample data.
m = zeros(11, 3);
% Set a few locations (7) to 3
randomLocations = randperm(numel(m), 7);
m(randomLocations) = 3
% Now we have our matrix and we can begin.
[rows, colms] = size(m);
mOut = m; % Initialize
for row = 2 : rows
for colm = 1:colms
% Check column 1
if m(row-1, colm+1) == 3
mOut(row, colm) = 3
end
% Check column 2
if m(row-1, colm) == 3 || m(row-1, colm+2) == 3
mOut(row, colm+1) = 3
end
% Check column 3
if m(row-1, colm+1) == 3
mOut(row, colm+2) = 3
end
end
end
mOut % Print to command window
Hello Dear Image Analyst, could u plz reply. Thanks for all cooperation

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

태그

질문:

2019년 8월 4일

댓글:

2019년 8월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by