# MatPlanWDM v0.5

### Pablo Pavon Mariño (view profile)

29 Jan 2007 (Updated )

Educational network planning tool for the RWA problem in WDM networks (MILP and heuristic based)

array2vect.m
```% array2vect
%
%>> Usage:      [vectorA] = array2vect (arrayA)
%
%>> Abstract:   This function returns a vector ("vectorA") with the same elements as the N-Dimensions array "arrayA". The elements of "vectorA"
%               are taken ROW-WISE from "arrayA".
%
%>> Arguments:
%   o	In:
%    . arrayA:		The M-by-N-by-P-by... array which we wish to convert into a 1-by-M*N*P... vector
%
%   o Out:
%     vectorA:     The objective 1-by-M*N*P... vector consisted of the elements of "arrayA".
%
%
%
function [vectorA ] = array2vect (arrayA)

%Our objective is to get a conversion Array-to-Vector taking row-wise the elements from the array, but the built-in function 'reshape' does it taking column-wise
%the elements of the array. This is the reason of this function 'array2vect'. We also have to use the built-in function 'permute' to get it.

dimArray=size(arrayA); %This is a 1-by-N vector of dimension lengths.
orderOfDims=length(dimArray):-1:1; % We have to change the order of the dimensions of arrayA to be able to take row-wise the elementes from the array. We defined
%"orderOfDims" to get this.
permutedArrayA=permute(arrayA,orderOfDims); % The function 'permute' rearranges the dimensions of "ArrayA" so that they are in the right order by the vector
%  "orderOfDims". It transforms the M-by-N-by-P-by... array into the ...by-P-by-N-by-M array.
vectorA=reshape(permutedArrayA,1,prod(dimArray)); %The permuted array(...PxNxM)  is converted into a vector(M*N*P...)by utilizasing the function 'reshape', which takes
%the elements from 'permutedArrayA'columnwise instead rowwise, but the "permutedArrayA" has permuted the dimensions of the
%"arrayA". This fact balances the column-wise generating a taking row-wise of the elements of arrayA.

```