Assign null to rows of a matrix

조회 수: 79 (최근 30일)
Benedict Teng
Benedict Teng 2019년 9월 20일
댓글: Benedict Teng 2019년 9월 20일
Hi guys,
I wanted to assign increment rows of null to a variable "C". The variable C has a size of 138x6x69. My code is shown below.
a = 1;
for i = 1:69
C(1:a,:,i)=[];
a = a+2;
end
But the error was " A null assignment can have only one non-colon index.A null assignment can have only one non-colon index."
Can anyone teach me another way of modifying the code? I really need help.
Much Thanks
Ben

채택된 답변

Raj
Raj 2019년 9월 20일
You cannot assign 'null' like this to a 3D matrix while wanting to maintain the dimensions of the matrix. You can assign zero or NaN depending on what you want to achieve here.
  댓글 수: 7
Stephen23
Stephen23 2019년 9월 20일
편집: Stephen23 2019년 9월 20일
"but it seems like the matrix size change every time after I assign null the rows"
Because what you are doing is removing rows:
MATLAB does not have a "null" concept, even though you keep using this term. You can't "assign null" as you write, because "null" does not exist.
Can you suggest any better way to do this?
Collect all of the required indices into a vector, use it to remove all rows at once after the loop.
Benedict Teng
Benedict Teng 2019년 9월 20일
I've got it, thanks for the advices guys. Really appreciate it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by