필터 지우기
필터 지우기

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