I have a d-dimensional array, A, and vector inds with length equal to d. I would like to access the value of A at inds.
Ideally, I'd do something like A(*inds) (borrowing the unpacking syntax from Python). I'm not sure how to do this in MATLAB.
If I do A(inds) I actually get d separate values from A, which is not what I want. What I want is for element i of inds to be the ith parameter in the function call A().
An element in 2-dimensional array is accessed by using the subscripts. That is, row index and column index of the array. int x = a[1,1]; Console.
To access elements in a range of rows or columns, use the colon . For example, access the elements in the first through third row and the second through fourth column of A . An alternative way to compute r is to use the keyword end to specify the second column through the last column.
A multidimensional array in MATLAB® is an array with more than two dimensions. In a matrix, the two dimensions are represented by rows and columns. Each element is defined by two subscripts, the row index and the column index.
You can use the square bracket operator [] to concatenate or append arrays. For example, [A,B] and [A B] concatenates arrays A and B horizontally, and [A; B] concatenates them vertically.
One solution is to create a comma-separated list out of your vector of subscripted indices inds
. You can do this by converting it to a cell array using NUM2CELL, then using the {:}
syntax when indexing A
:
inds = num2cell(inds);
value = A(inds{:});
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