Deleting the row of a 3D matrix with a condition

조회 수: 9 (최근 30일)
Ashane Fernando
Ashane Fernando 2019년 2월 15일
댓글: Ashane Fernando 2019년 2월 22일
I have a simple 3D matrix. Every time I do this operation on the (:,:,1) matirx it gives me an error saying "A null assignment can have only one non-colon index." I dont understand this. But in a simple 2D matrix it works. If I assign "NaN" instead of "[]" then the second row is assigned with NaN NaN values (in 3D). Can I not delete the row in a 3D matrix? Appreciate some insight to this.
A(:,:,1) = [1 2 ; 0 5 ; 7 8 ];
A(:,:,2) = [10 11 ; 1 14 ; 0 17 ];
A((A(:,1,1).*A(:,2,1))==0,:,1)=[]
  댓글 수: 1
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 2월 15일
Look here you will get the exact answer
As per undestanding from your question, you have to delete the complete plane, not a row line.

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

채택된 답변

Jan
Jan 2019년 2월 15일
편집: Jan 2019년 2월 15일
Of course you cannot delete one row in a 3D array: The resulting array must have the same length for all subvectors. Removing a row from a 3D array is equivalent to removing one element from a matrix: The result would not be rectangular anymore, but matrices must have the same number of elements for all rows, and all columns, respectively.
A(:,:,1) = [1 2 ; 0 5 ; 7 8 ];
A(:,:,2) = [10 11 ; 1 14 ; 0 17 ];
B = A;
B(:, :, 1) = [] % Working
A(1, :, 1) = [] % Error: output cannot be a valid array
Therefore I cannot guess, what you expect as output and cannot suggest a solution. Assigning NaN to a row works, because this does not change the number of elements.
  댓글 수: 5
Jan
Jan 2019년 2월 15일
Sorry, I cannot follow you. I asked you what happens if you have only 1 zero in the input, such that you cannot remove a single subvector without destroying the rectangular shape of the array. Now your answer is: If the array contains one 0 only, then it actually contains two? What does this mean?
If all submatrices contain the same number of zeros, than you can remove the corresponding rows or columns or what you want. But you did not clarify yet, if this is guaranteed.
Ashane Fernando
Ashane Fernando 2019년 2월 22일
Hi Jan,
I realised I was looking at a wrong thing. I figured that I cannot delete a row from a 3d matrix.
I converetd the necessary values to a 2D matrix and did the manipulation as I required.
Thanks for showing me some light.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by