Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a 3D array to a 2D array in Matlab

Tags:

arrays

matlab

Suppose I have a 4x2x2 array such that

val(:,:,1) =

    1.0000   18.2190
    1.0000   15.4650
   12.0223   76.2841
   64.1669  104.7139

val(:,:,2) =

    1.0000   18.2190
   18.2190   18.6414
   11.5436   74.6475
   74.7046  110.4268

I am trying to "flatten" this 3D array into a 2D array so that it looks something like this

val(:,1) = 

    1.0000   
    18.2190
    1.0000   
    15.4650
    12.0223   
    76.2841
    64.1669
    104.7139

Is there a shorthand method for doing this so I can avoid using for-loops?

like image 557
Johnli089 Avatar asked Feb 27 '26 13:02

Johnli089


1 Answers

You can also use pagetranspose which makes it very short:

reshape(pagetranspose(val),[],1)
like image 136
Till Avatar answered Mar 01 '26 13:03

Till



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!