フィルターのクリア

Removing multiple columns from a matrix

9 ビュー (過去 30 日間)
Sarah Nolt-Caraway
Sarah Nolt-Caraway 2022 年 4 月 19 日
回答済み: Jon 2022 年 4 月 19 日
I have a data matrix a = 630x3000, and I want to delete the first few columns based on length of another matrix that holds the number of columns i need to delete for each row, b = 630x1.
For example for the first row (1x3000), I need to delete 0 columns , but the next row (2x3000), I need to delete 6 columns. I would then like to pad zeroes onto the end of the matrix based on how many column I removed. This is to ensure the matrix stays the same size.
I understand how to delete indiviudal columns, but I am not sure how to implement this in a loop based on a changing value.
I believe it is something like this, but it is only removing that column number instead of the first 6, etc...
for i = height(a)
a[:b(i)] = []
a =[a(i) zeros(1,b(i))]
end

採用された回答

Jon
Jon 2022 年 4 月 19 日
I think this will do what you want
for k = 1:numel(b)
a(k,:) = [a(k,b(k)+1:end),zeros(1,b(k))]
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by