Removing multiple columns from a matrix

9 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by