Multidimentional Arrays of variable Size without using cells Matlab - arrays

I need to store multiple measurements which are contained in arrays of variable elements size (their datatype is double ) in an single array so as to use a specific matlab function . The input of this function has to be an array so I can't use the Cell data type and I know that by definition you can't have a different number of elements in different slices of the same dimensions . So my quetion is do you have a suggestion of having an array of arrays of variable size in Matlab without using Cell ?
Thank you .

Related

Appending to cell array matlab

I am new to matlab. I have one question about datatypes.
I have an array of the cell array type. In the variables window it shows me it as 190x1 double.
I have two questions.
What is the purpose of the cell array type if there is the matrix type ?
How to append another similar array to the column of an existing array. For example I have two arrays 190x1 double I wan't a new array to be 380x1 double
I would be grateful for any help.
Thanks
I'd encourage you to browse the documentation for cell arrays. One of the most common uses as it states is mixed size or mixed type data...among other uses.
Cell arrays commonly contain either lists of text strings,
combinations of text and numbers, or numeric arrays of different
sizes.
To append two arrays you could do this. It will place the two vectors end to end.
X=ones(190,1);
X =[X; X];

Matlab - Access cell array by name

I wrote several cell arrays I read from txt-files in cell arrays within the MATLAB Workspace. I wrote a cell array 'Names', containing the names of the other cell arrays I assigned. The txt-files can have varying names, therfore I want to use this dynamic naming.
Now I would like to the cell arrays dynamically by using the name (string) from 'Names'. Is this possible? Which syntax do I have to use?
Logically Names{i} gives back the name of the cell array in position i. However using Names{i}.n does not work.
I could not find anything in the MATLAB documentation either..

How to save matrices in an array

I was wondering is it possible in C language to save couple of matrices in an array and how to do that? Like, I pass a static matrix to a function and in a several steps I use the same matrix for different calculations, so I need to save every matrix with different result somewhere, so is it possible to save matrix as element of an array?
so is it possible to save matrix as element of an array?
Yes, you can use a three dimensional array to store it's elements as matrices. Something like array[no_of_matrices][row_no][column_no] would do fine
example:
int arr[2][2][2];
// this would store 2 matrices of dimensions 2*2
Additionally, if you want arrays of different dimensions then you can create **array[no_of_matrices] and use dynamic memory allocation to allocate memory according to required dimensions of each matrix.

Declaring arrays of different sizes within a pre-existing array in python

I have been trying to declare a three dimensional array with the following constraints using numpy in Python 2.7.3:
1.) MyArray(First, Second, Third)
2.) First has 11 elements
3.) Second has 14 elements
4.a) The Third dimension varies in size depending on the element of the First dimension
4.b) If First=8 then Third=988
4.c) Else if First=10 or First=11 then Third=640
4.d) Else Third=494
Is this possible with arrays or should I be using structures?
Thank you in advance,

How to flatten (reshape to 1D) an array of arbitrary dimension in Labview

Let A be an array of arbitrary dimension (2 or 3 in my case).
How can I flatten (reshape to 1D) this array without knowing in advance the number of dimensions ?
If I knew the number of dimensions, I could easily obtain the total number of elements (by using a combination of "Array Size" function) and then reshape A to 1D using this number.
Unfortunately, the "Array Size" function itself returns an array whose number of elements is equal to the number of dimensions, which brings us back to the initial problem.
I have "solved" the problem by creating a function (VI) that returns the total number of elements of a 3D array (the most common type of arrays that I expect to handle), so that I can give this as an argument to the Reshape function. Problem: it won't accept a 2D array, even though the algorithm would work with such an array ! (it seems that in Labview, array controls are strict about the number of dimensions they accept, which isn't the case in Matlab for instance).
A nice solution would be a simple way to multiply all the elements of the array given by "Array Size" to quickly get the total number of elements, without having to wrap this in a sub VI.
Overall, isn't there a simple and efficient way to solve this problem ? It should be quite standard..
I belive this is what you are looking for :
http://zone.ni.com/reference/en-XX/help/371361E-01/glang/reshape_array/
You would do :
n-DimInputArray --> ArraySize --> 1D_SizesOUT
This returns a 1D array containing the sizes of all of the array dimensions.
You then go :
1D_SizeOUT --> MultiplyArrayElements --> NumberOfElementsIn_n-DimInputArray
This value goes in as the dimension size for ReshapeArray - done.
http://zone.ni.com/reference/en-XX/help/371361E-01/glang/array_size/
http://zone.ni.com/reference/en-XX/help/371361E-01/glang/multiply_array_elements/
Here's a snippet of the above code:
Just get the array size of the array size and you'll get the number of dimensions...
To put this into a subvi, transform your unknown array into a variant and give this variant and the number of dimensions into the subvi. Inside the subvi, "Variant to Data" with an array of your dimension.

Resources