how to fill gaps in a matrix with a numbers using interpolation to develop a contour.

M =
0 0 0
0 0 3
0 3 0
3 0 3
0 3 0
0 0 3
3 0 0
0 0 0
in this M matrix, using interpolation i want to fill gaps with 3s between any 3s. for example, in first column, first 3 is in the 4th row and last 3 is in the 7th row. i want to fill rows 5 and 6 also with 3s. same for other columns.
Thanks and regards for all cooperation

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 7월 27일
편집: Andrei Bobrov 2019년 7월 27일
M(cumsum(M) & cumsum(M,1,'reverse')) = 3;
or for:
M =[0 0 0; 2 2 3; 3 3 0; 0 0 0; 3 3 0; 2 2 3; 0 0 0; 3 3 2; 0 0 0; 3 3 3];
s = join(string(M)','');
[a,b] = regexp(s,'30+3');
lo = false(size(M));
for ii = 1:numel(a)
for jj = 1:numel(a{ii})
lo(a{ii}(jj)+1:b{ii}(jj)-1,ii) = true;
end
end
M(lo) = 3;

댓글 수: 1

Thanks bro Andrei for your continuous contributions in the research. Warm regards.

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

추가 답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 7월 27일
편집: KALYAN ACHARJYA 2019년 7월 27일
M =[0 0 0
0 0 3
0 3 0
3 0 3
0 3 0
0 0 3
3 0 0
0 0 0]
[rows colm]=size(M);
for i=1:colm
idx=find(M(:,i)==3);
idx_update=idx(1):1:idx(end);
M(idx_update,i)=3;
end
M
Loop can be avoided. Wait for experts comments.
Result:
M =
0 0 0
0 0 3
0 3 3
3 3 3
3 3 3
3 0 3
3 0 0
0 0 0

댓글 수: 5

M =[0 0 0; 2 2 3; 3 3 0; 0 0 0; 3 3 0; 2 2 3; 0 0 0; 3 3 2; 0 0 0; 3 3 3]
[rows colm]=size(M);
for i=1:rows-2
for j=1:colm
if (M(i,j)==3 && M(i+2,j)==3)
M(i+1,j)=3;
end
end
end
M
Unabled to fixed it without loop. wait for experts answer.
Just I saw that you have posting duplicate question., Please donot post multiple same question, people invest their important time on user question.
Mr. Kalyan, 3rd column is not changed.
Your comment:
"i mean to fill 3s only only 3 and then the next 3, not in all."
There is no 3 0 3 combination in the 3rd column.
Mr. Kalyan, 3 and next 3 positions should be filled with 3s. For example 3 0 0 0 0 3. So it should be 3 3 3 3 3 3.
Can the gaps only be in a single column?

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

카테고리

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

제품

질문:

2019년 7월 27일

댓글:

2019년 7월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by