Removing multiple columns from a matrix

10 views (last 30 days)
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

Accepted Answer

Jon
Jon on 19 Apr 2022
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

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!