MATLAB Answers

How do i declare an array for cell in Mex?

2 views (last 30 days)
Hariprasad on 31 Oct 2014
Edited: Hariprasad on 6 Nov 2014
Edited my original post.
I'm loading a mat file which has data as cell array(sized 1000x6). I have reached till the stage where I load the mat file but I want to check if the data from mat file was loaded successfully. I have attached the code here after making the corrections as suggested. I have compiled the code without error but probably memory leak issue has come up because when I run the code, Matlab crashes.
The cell array in the Mat file is a collection of strings and numbers like:-
Filename TotalData Rows Columns Date_created All_Ids
'Data_1' 1000 1000 16 '10-Jul-2013' 1000x1 double
'Data_2' 1000 1000 16 '10-Jul-2013' 1000x1 double
'Data_4' 1000 1000 16 '10-Jul-2013' 1000x1 double

Answers (1)

Geoff Hayes
Geoff Hayes on 31 Oct 2014
Edited: Geoff Hayes on 3 Nov 2014
Hariprasad - it would be easier to point out the problems if you had included all of your code, because it is unclear what line 73 is given that you haven't pasted 73+ lines of code in your question. In the future, please just attach your code to your question using the paperclip button. Given that this is a c file, you would have to change the extension to txt or m just to allow you to attach it.
A couple of problem is with how you try to create the cell arrays. Look at the first line
Dataset_info = mxCreateCellArray(ndims,dims);
Your are passing in ndims and dims, neither of which have been initialized at this point, and they are of the wrong data type. From the documentation for mxCreateCellArray, its function signature is
mxArray *mxCreateCellArray(mwSize ndim, const mwSize *dims);
This means that ndim is of type mwSize and dims is an array of type mwSize. They would need to be declared as
mwSize ndims;
mwSize dims[3];
and defined as (for example)
ndims = 3;
dims[0] = 3;
dims[1] = 2;
dims[2] = 1;
So what, in your code or from your file, should determine the number of dimension (and their sizes) for the Dataset_info and Dataset_OP arrays?
Start with fixing this problem, and then we'll go from there.
As James pointed out (see comment below), no memory has been allocated to the dims array. So have replaced
mwSize* dims
mwSize dims[3];
Hariprasad on 6 Nov 2014
Oh yes, the mat file first loaded( DsetmatFile ) has only one variable. So I hope the matGetVariableInfo would give the name of the data variable stored in the mat file.
Yes sir. The first value is a string in the cell array. The values are ' Data_1 ', ' Data_2 ',etc which are the mat file names in the first column of the DsetmatFile opened. These mat files would contain a double array of about 1000xN values each. I tried the mxGetCell and was able to load the correct mat file.
Thank you!!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!