Aligning columns in a matrix by padding with zeros

I have a matrix A below. The values in each column are all roughly 100 apart, but some of them are missing some values. They represent loci of peaks in a graph. I want to make a matrix B that puts the zeros where they need to be: where a value in a column is "skipped"
1698 1696 1699
1826 1819 1816
1928 1921 1921
2063 2065 2059
2184 2186 2181
2399 2278 2270
2544 2373 2373
2655 2449 2555
2792 2552 2652
0 2657 2796
0 2794 0
e.g. column 1 should be
1698
1826
1928
2063
2184
0
2399
0
2544
2655
2792

2 件のコメント

KSSV
KSSV 2020 年 8 月 20 日
How you will determine that a column is skipped?
AbioEngineer
AbioEngineer 2020 年 8 月 20 日
Hi KSSV, I'm new to machine learning and am not sure how to determine if a value in a column is skipped. I guess maybe I can find the column with the most values, and and compare each row value of a column with the distributed values of each row?

サインインしてコメントする。

 採用された回答

Stephan
Stephan 2020 年 8 月 21 日

0 投票

Under the assumption that you have at least one not corrupted column (here column 2), this might work:
A = [1698 1696 1699
1826 1819 1816
1928 1921 1921
2063 2065 2059
2184 2186 2181
2399 2278 2270
2544 2373 2373
2655 2449 2555
2792 2552 2652
0 2657 2796
0 2794 0]
non_corrupt_col = 2;
b = fix(A/100) - fix(A(:,non_corrupt_col)/100);
while sum(b==1,'all') ~=0
b = fix(A/100) - fix(A(:,non_corrupt_col)/100);
[r,c] = find(b==1,1);
A(r+1:size(A,1),c) = A(r:size(A,1)-1,c);
A(r,c) = 0;
end
disp('result:')
A
Results in:
result:
A =
1698 1696 1699
1826 1819 1816
1928 1921 1921
2063 2065 2059
2184 2186 2181
0 2278 2270
2399 2373 2373
0 2449 0
2544 2552 2555
2655 2657 2652
2792 2794 2796

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

質問済み:

2020 年 8 月 19 日

回答済み:

2020 年 8 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by