MATLAB Answers

Trouble w/ MLGetVar and MLGetMatrix using Dataset arrays

2 views (last 30 days)
Jason
Jason on 24 Aug 2012
I have a 54 X 10 dataset set array that I can't get out of MatLab and into MS Excel/VBA. Using MLGetVar the following code breaks after the first iteration of 'y'. Hovering over the variable is shows as empty.
TEMPRowSize = 54
TEMPColSize = 10
MLGetVar "FirstPageTEMP", FirstPageTEMP
For x = 1 To TEMPRowSize
For y = 1 To TEMPColSize
.Cells(x, y).value = FirstPageTEMP(x, y)
Next y
Next x
End With
Using MLGetMatrix returns no values to my worksheet at all.
MLGetMatrix "FirstPageTEMP", ActiveSheet.Range("A1").Address
MatlabRequest
Any ideas? Please help jason

Accepted Answer

owr
owr on 25 Aug 2012
I highly doubt that MlGetVar/Matrix support dataset arrays which are in the Statistics Toolbox. It would be nice if they did, even better if dataset arrays were moved to core MATLAB. I think you're going to need to write your dataset arrays to MATLAB primitives and use these instead.
  2 Comments
owr
owr on 30 Aug 2012
I think thats probably the best approach. 2012A has a method called "dataset2cell", if you have access to a newer version maybe that would work? "cellstr" only works if all the columns are atrings of some type, wont work with numeric data.
Otherwise, you can write a method like this yourself. Its not "elegent" but likely what similar built in MATLAB functions are doing.
If your dataset array is named "ds", grab the column names using:
cn = get(ds,'VarNames')
and then loop over each column using this type of syntax:
ds.(cn{i}) (i is your loop index)
You can test each column's type using "iscell" or "isnumeric", etc. and convert then using something like "num2cell" or "mat2cell".

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by