File Exchange

image thumbnail

Converting a Multi-dimensional Array to a Table

version 1.0.1 (5.28 KB) by GallVp
mulDimArray2table function converts a multi-dimensional MATLAB array of form AxBxCx... to a MATLAB table.

8 Downloads

Updated 28 Jul 2019

View License

mulDimArray2table function converts a multi-dimensional MATLAB array of form AxBxCx... to a MATLAB table with dimension indices as separate columns for identification. This function is intended for exporting data from MATLAB in long format to R for performing a statistical analysis.

Cite As

GallVp (2019). Converting a Multi-dimensional Array to a Table (https://www.mathworks.com/matlabcentral/fileexchange/72224-converting-a-multi-dimensional-array-to-a-table), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

GallVp

Thanks Stephen. I have added your implementation. Could not find your name in acknowledgements so mistakenly added one of your projects. Hope you don't mind that.

Simpler method based on NDGRID and ARRAY2TABLE:

C = arrayfun(@(n)1:n,size(A),'uni',0);
[C{:}] = ndgrid(C{:});
C = cellfun(@(m)m(:),C,'uni',0);
T = array2table([C{:},A(:)])

Add variable names etc. as required.

Updates

1.0.1

Added Stephen Cobeldick's implementation

MATLAB Release Compatibility
Created with R2019a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags
Acknowledgements

Inspired by: Viva la Resistance!

mulDimArray2table

mulDimArray2table