How to delete 0 elements contained in a 3D array and store them in a new 3D array

2 views (last 30 days)
In the data stored in DividedW (3D array), in order to delete the 0 element, store the digital element in the ZERO array (3D array),I want to store the data with 0s removed in a new matrix DividedX (3D array). We are considering the program below, but as it isSince 0 is deleted, the array size is different for each Num, so an error occurs.I would appreciate it if you could teach me if there is any good way.
for Num = 1:(div1*div2)
ZERO(:,:,Num) = DividedW(:,:,Num) ~= 0;
RX(:,:,Num) = DividedX(ZERO(:,:,Num))
end
Also,
RX(:,:,Num) = DividedX(ZERO(:,:,Num))
         ↓
RX(:,:,Num) = DividedX(:,:,Num)(ZERO(:,:,Num))
I think that is the correct notation, but in this case () overlaps and an error is displayed.Is there any other notation method?
  4 Comments
Rik
Rik on 19 Jan 2021
That is not possible. Each page of a Matlab array must have the same number of rows and columns. If you want this, you could use a cell array. Whether that will solve your issue depends on what you want to do next.
一成 萬膳
一成 萬膳 on 19 Jan 2021
Thank you for your answer. Due to the specifications of my program, cell arrays cannot be used, so I think it is difficult to apply. So let's look for another way that doesn't use 3D arrays. Thank you for the place busy.

Sign in to comment.

Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!