T
T
tj572019-06-05 01:49:27
Mathematics
tj57, 2019-06-05 01:49:27

How to index inside a 4 dimensional matrix in Matlab?

There is a 10x10 matrix, each element of which is an array of 3 elements. To index by matrix elements and write vectors with the same values ​​into it, you need to do this:

for i = 1:10
    for j = 1:10
        matrix(:, :, i, j) = [1; 2; 3];
     end
end

How can you get every 3rd element from each vector from the resulting matrix? And is it generally possible?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2019-06-05
@tj57

How can you get every 3rd element from each vector from the resulting matrix?

Indexes in matlab can be given in the format: start:step:end
For your purpose, simply set step 3 in the corresponding index and get every third element.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question