how to fill gaps in a matrix with a numbers using interpolation to develop a contour.
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
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 件)
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!