set efficently specific rows in a sparse matrix to 0
이전 댓글 표시
Hello comunity,
I have a sparse matrix J and i want to set specific rows to 0.
My code's like this:
J = sparse(blkdiag(rand(1000,1000),rand(100,100),rand(200,200))); % just for example
vec = [1:10,20:400,800:1100]'; % just for example
J(vec,:) = 0;
Is there a faster way how to set the specific lines of J to 0?
best regards,
Marko
채택된 답변
추가 답변 (1개)
Marko
2021년 9월 3일
댓글 수: 1
Walter Roberson
2021년 9월 3일
In your posted question, vec is a column vector. And the code I posted works when vec is a column vector. But if vec were a row vector instead then you would get the error you mention.
카테고리
도움말 센터 및 File Exchange에서 Weather and Atmospheric Science에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!