MATLAB Answers


How can data in the form of cell arrays be used to train CNN using deeplearning toolbox ?

Asked by Abdulla Lutfi on 10 Feb 2019
Latest activity Commented on by Johanna Pingel on 15 Feb 2019
Hi everyone , Im new to the field of AI.
I have huge amounts of data arranged in the form of cell arrays. These data belong to 5 different classes and I want to use alexnet/googlenet to train my CNN for classification . Apparently The MATLAB deeplearning toolbox only supports image files. is there anyway to make it accept the cell arrays as input ? or do I need to change the form of the data ? any ideas ? can someone provide a simple code please.


Sign in to comment.

1 Answer

Answer by Johanna Pingel on 12 Feb 2019

Are your image names in a cell array? If so, it's simply:
imds = imageDatastore(a); % where a is your cell array of filenames.
If your image data are in cell arrays, which I'm guessing is the case, it's slightly harder but not really. Write out the files into 5 subfolders based on your categories, then use imageDatastore.
%% write data out to files
for ii = 1:10 % or your number of files
imwrite(a{ii},"allfiles/category1/filename" + ii + ".png") % where a is your cell array of images
You'll have to change this code so that each file goes into the right folder based on category, but for me, it always comes back to datastores, since they are your simple input to training. Let me know if you have any questions


The problem is , the data I have doesnt represent images , it is 4 columns , 1 column is representing time and the other three (I1,I2,I3) represent 3 current signals graphs that I got from simulink simulations. When I used your code I got this result for all data ! check it out
As you can see all I get is a black line for everything , I dont think the deep learning tool box can get any useful information from this. is there any other solution for this issue ?
really thankful for the support and help.
After re-reading your question, I realized I made up the idea that your data was images, since that's what I work on all day. You're looking for a time series example for deep learning then:
Perhaps one of these examples is close? The good news is it looks like some of these examples use cell arrays as input!

Sign in to comment.