Azzera filtri
Azzera filtri

Removing multiple columns from a matrix

9 visualizzazioni (ultimi 30 giorni)
Sarah Nolt-Caraway
Sarah Nolt-Caraway il 19 Apr 2022
Risposto: Jon il 19 Apr 2022
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

Risposta accettata

Jon
Jon il 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

Più risposte (0)

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by