Convert cell arrays to 4-D array
이전 댓글 표시

I've got a 35*10 cell array, which contains multiple matrices with the same size(256*256). I want to convert it into a 4-D array(256*256*10*35).
댓글 수: 1
Stephen23
2019년 4월 23일
Important note to future readers: the accepted answer mixes up the data!
채택된 답변
추가 답변 (1개)
Stephen23
2019년 4월 22일
Where C is your cell array:
M = cell2mat(permute(C,[4,3,2,1]))
댓글 수: 8
Wenyi Xiao
2019년 4월 22일
You should know that the answer you accepted gives the data in an mixed up order.
debojit sharma
2023년 6월 16일
what is [4,3,2,1]? Please kindly explain what will be these values if I have a cell array of size 1* 135

Because your cell array is "one dimensional" you do not need PERMUTE, you can simply use a comma-separated list. Lets first create some fake data:
format compact
xTrain = {rand(2,2,4),rand(2,2,4),rand(2,2,4)}
A = cat(4,xTrain{:}) % this is all you need
Alternatively you could use RESHAPE and CELL2MAT (complex and slower):
A = cell2mat(reshape(xTrain,1,1,1,[]))
The original answer requires permute because the cell array is a matrix, and then OP wanted to permute the cell array dimensions 1&2 to become dimensions 4&3 of the output array respectively. Your case is simpler: you only want to permute cell array dimension 2 to dimension 4. This can be achieved using the code I gave above.
But if you really want to use PERMUTE here it is:
% vvvvv the order of these is not important
% v move cell array 2nd dim to 4th dim
A = cell2mat(permute(xTrain,[1,3,4,2]))
debojit sharma
2023년 6월 16일
debojit sharma
2023년 6월 16일
I am trying to implement the code given in the following link with my own dataset:
I am getting the following errors in the Train model part:

I can make out that there is some issue happening with the custom functions ('modelLoss', 'elboLoss') given in this link. But I am unable to understand how can I resolve these issues. Please kindly guide me @Stephen23 sir. I will be thankful to you.
Stephen23
2023년 6월 17일
@debojit sharma: ask a new question. Give sufficient information that we can replicate the error.
debojit sharma
2023년 6월 17일
@Stephen23 sir, I am trying to implement the code to train VAE for image generation given in the following link using by own dataset of RGB images of size 200*200.
I am getting the following errors in the Train model part:

The code of VAE in the above link is using MNIST dataset images as input to encoder of VAE and it is being said that the decoder of VAE will output an image of size 28-by-28-by-1. But I am trying to generate RGB image of size 200*200 by training this VAE model given in the link. So, my input image is a RGB image of size 200*200. I am getting the above mentioned error in the train model part. I am not able to resolve these errors. So, please kindly guide me @Stephen23 sir regarding what changes I will have to make in this code so that I can train these VAE model to generate RGB image of size 200*200. I will be thankful to you.
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!