View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

Be the first to rate this file! 0 Downloads (last 30 days) File Size: 3.83 KB File ID: #36968 Version: 1.1




04 Jun 2012 (Updated )

Convert N-dimensional cells of K-dimensional matrices to N*K matrices.

| Watch this File

File Information

Neither previous CELL2NUM or CELL2MAT can deal with cells and matrices of arbitrary dimensions. Hence my submission.

This function convert a multidimensional cell INPUT composed of multidimensional matrices to a matrix OUTPUT. The only requirement is that all the matrices have the same dimensions.

Given N = size(INPUT) and K = size(INPUT{1}) the size of OUTPUT will be [N x K].

Example 1:
N => [2 3]
K => [4 3]
OUTPUT => [2 3 4 3]

Moreover it is possible to set parameters in order to eliminate eventual singleton dimensions or convert either N or K to equivalent vectors.

Example 2:
N => [1 3]
K => [4 1 2]
OUTPUT => [3 4 2]

Example 3:
(changing parameters)
N => [2 3]
K => [4 3]
OUTPUT => [6 4 3]

Example 4:
(using parameters)
N => [2 3]
K => [4 3]
OUTPUT => [2 3 12]

Example 5:
(using parameters)
N => [2 3]
K => [4 3]
OUTPUT => [6 12]

Required Products MATLAB
MATLAB release MATLAB 7.14 (R2012a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
12 Feb 2016 Roberto Calandra

Hi Rafik,
If I understood correctly you would like to convert a Matrix (e.g. A =[1,2;3,4]) into a vector (e.g., A = [1,2,3,4]). To do this you could simply use the command: A(:)
Is this what you asked?

Comment only
12 Feb 2016 Rafik

Rafik (view profile)

Thanks Roberto for the codes. My problem is follow: I have a matrix data and I want to convert it to one line. Could you help with the code please.

Comment only
06 Jun 2012 Roberto Calandra

Yes, you are correct, the examples in the description are abstract. However "Demo_cell2num" contain numerous real examples as well as many combinations of the possible parameters that you can use.
I'll try to change the description to explain it better.

Comment only
05 Jun 2012 Jan Simon

Jan Simon (view profile)

The examples in the description are abstract. An explicit code would be more useful than the need to guess, what "(using parameters)" is or what "OUTPUT => [2 3 12]" could mean.
Please improve these details.

Comment only
05 Jun 2012 1.1

Typo fixes

Contact us