In Matlab, I want to create a two-dimensional array. However, I cannot create a matrix, because the rows are all different lengths.
I am new to Matlab, and I would normally do this in C++ by creating an array of pointers, with each pointer pointing towards its own array.
How should I do this in Matlab? Thanks.
You can use cell arrays, which can contain data of varying types and sizes.
Like this:
data = {[1]; [2,2]; [3,3,3]};
Check out here for more examples.
You could use a cell array:
C = {[1,2,3];
[1,2,3,4,5];
[1,2]};
Or pad with NaN
or 0 or Inf
etc
N = [1, 2, 3, NaN, NaN;
1, 2, 3, 4, 5;
1, 2, NaN, NaN, NaN]
It really depends on what you will be doing with your data next
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With