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!