Creating a matrix of specific size, in which I can input each element value.
How to create a matrix of size N×N that has ones in the border and zeros inside?
How to create a matrix with arbitrary dimensions
how to generate matrix of size 10X10?
I need to be able to create a matrix or pre-allocate a matrix from given ROW and COLUMN inputs. I've found that if I do something like:
a = zeros(10,12)
SIMULINK grants it as a fixed size matrix.
But if I do stuff like following:
function y = matrix(row,col)
a = zeros(row,col)
y = a
SIMULINK thinks the dimensions are variable. Thus it's a variable sized matrix. So I can't wire the output to another block which wants fixed size matrix.
What is the solution here, if I want to take my matrix dimensions from variables?
40000 * 40000 * 8 bytes per number = 12 GB, surely you won't have enough memory.
To create a huge matrix with lots of zeros, you need a sparse matrix:
m = sparse(40000, 40000)
To create an array of variants, you can use a cell array:
m = cell(3, 1)
m(1) = [1,2,3]
m(2) = [2,4,6,8,10]
m(3) = 6+6i
There are many things you can do, as the various answers point out. The correct answer depends on your actual problem. Brute force creation of such a large array is impossible without a 64 bit version of matlab plus enough memory to store that large an array, or storing the array in some other way. You can store the array offline, only bringing in what you need as you use it.
For example, if these numbers will always be small integers, then use uint8 or int8, or a logical array, even a single array, all of which will reduce the memory requirements compared to double arrays. Or use a sparse storage form as appropriate. Much depends on what you will do with the array.
As far as a variable number of elements in a row, use a cell array here, not a flat traditional array.