[Scilab-users] concatenate hypermatrices along the 3rd dimension

classic Classic list List threaded Threaded
4 messages Options
Antoine Monmayrant Antoine Monmayrant
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] concatenate hypermatrices along the 3rd dimension

Hi all,

I'm trying to stack (or concatenate) 3D matrices (hypermatrices) along
the 3rd dimension.
(The goal is to perform zero-padding along the 3rd dimension).
So far, the only - and ugly - solution I've found is the following:

//my padding
a=zeros(2,2,3);
//my data
b=a;
b(:,:,1)=[111,112;121,122];
b(:,:,2)=[211,212;221,222];
b(:,:,3)=[311,312;321,322];
// zero-padded data
padded_b=matrix([a(:);b(:);a(:)],[size(a,1),size(a,2),3*size(a,3)]);
Is there a solution that is less convoluted (and maybe more efficient)
than resorting to this mix of "(:)" and "matrix"?

Thanks in advance,

Antoine

PS: If you are curious, I'm looking at the time evolution of a 2D image
and need to do zero-padding and fft for spectral analysis : the 2 first
dimensions are space ones (x,y), while the 3rd one is temporal evolution.

--
+++++++++++++++++++++++++++++++++++++++++++++++++++++++

  Antoine Monmayrant LAAS - CNRS
  7 avenue du Colonel Roche
  BP 54200
  31031 TOULOUSE Cedex 4
  FRANCE

  Tel:+33 5 61 33 64 59
 
  email : [hidden email]
  permanent email : [hidden email]

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] Re : concatenate hypermatrices along the 3rd dimension

Hello Antoine,

Please check cat(3, ..) to concatenate along the 3rd (or any) dimension.
Please check resize_matrix() to padd an hypermatrix (with what you want).

Regards
Samuel

----- Mail d'origine -----
De: antoine monmayrant <[hidden email]>
À: International users mailing list for Scilab. <[hidden email]>
Envoyé: Mon, 08 Oct 2018 14:13:37 +0200 (CEST)
Objet: [Scilab-users] concatenate hypermatrices along the 3rd dimension

Hi all,

I'm trying to stack (or concatenate) 3D matrices (hypermatrices) along
the 3rd dimension.
(The goal is to perform zero-padding along the 3rd dimension).
So far, the only - and ugly - solution I've found is the following:

//my padding
a=zeros(2,2,3);
//my data
b=a;
b(:,:,1)=[111,112;121,122];
b(:,:,2)=[211,212;221,222];
b(:,:,3)=[311,312;321,322];
// zero-padded data
padded_b=matrix([a(:);b(:);a(:)],[size(a,1),size(a,2),3*size(a,3)]);
Is there a solution that is less convoluted (and maybe more efficient)
than resorting to this mix of "(:)" and "matrix"?
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: concatenate hypermatrices along the 3rd dimension

In reply to this post by Antoine Monmayrant
Hello Antoine,

Why not write:

padded_b=zeros(2,2,9);
padded_b(:,:,4:6)=b;

?

S.

Le 08/10/2018 à 14:13, [hidden email] a écrit :

> Hi all,
>
> I'm trying to stack (or concatenate) 3D matrices (hypermatrices) along
> the 3rd dimension.
> (The goal is to perform zero-padding along the 3rd dimension).
> So far, the only - and ugly - solution I've found is the following:
>
> //my padding
> a=zeros(2,2,3);
> //my data
> b=a;
> b(:,:,1)=[111,112;121,122];
> b(:,:,2)=[211,212;221,222];
> b(:,:,3)=[311,312;321,322];
> // zero-padded data
> padded_b=matrix([a(:);b(:);a(:)],[size(a,1),size(a,2),3*size(a,3)]);
> Is there a solution that is less convoluted (and maybe more efficient)
> than resorting to this mix of "(:)" and "matrix"?
>
> Thanks in advance,
>
> Antoine
>
> PS: If you are curious, I'm looking at the time evolution of a 2D
> image and need to do zero-padding and fft for spectral analysis : the
> 2 first dimensions are space ones (x,y), while the 3rd one is temporal
> evolution.
>

--
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: Re : concatenate hypermatrices along the 3rd dimension

In reply to this post by Samuel GOUGEON
Le 08/10/2018 à 15:30, [hidden email] a écrit :
Hello Antoine,

Please check cat(3, ..) to concatenate along the 3rd (or any) dimension.
Please check resize_matrix() to padd an hypermatrix (with what you want).

In your specific padding case, you may better use

b =  cat(3,[111,112;121,122], [211,212;221,222], [211,212;221,222])
padded_b =  cat(3,zeros(b),b,zeros(b))


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users