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
댓글 수: 1
awezmm
2019년 7월 27일
Do you need to find gaps horizontally too, or only vertically?
채택된 답변
추가 답변 (1개)
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
KALYAN ACHARJYA
2019년 7월 27일
편집: KALYAN ACHARJYA
2019년 7월 27일
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.
M.S. Khan
2019년 7월 27일
KALYAN ACHARJYA
2019년 7월 27일
편집: KALYAN ACHARJYA
2019년 7월 27일
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.
awezmm
2019년 7월 27일
Can the gaps only be in a single column?
카테고리
도움말 센터 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!