Hello everyone,
I have a 10x10x10 matrix of which I want extract element (10,4,10),(9,4,9),(8,4,8) and so on… then element (10,5,10),(9,5,9),(8,5,8) and so on… then store these values as consecutive entries in vectors, and then create a matrix out of the vectors, like so:
m = rand(10,10); vec(1)_1 = m(10,4,10) % first vector, first element
vec(2)_1 = m(9,4,9) % first vector, second element
... vec(1)_2 = m(10,5,10) % second vector, first element
vec(2)_2 = m(9,5,9) % second vector, first element
... mat(i,:) = vec_1, vec_2, vec_3, etc. % matrix containing vectors as columns
My take on it so far is the following:
m = rand(10,10); for i = 1:10 for k = 10:-1:1 vec(i) = m(k,4:7,k) mat(i,:) = vec_1, vec_2, vec_3, etc. end end
I know the problem is that I'm looping over all then numbers in k before jumping to the next i, which means only the last k will get stored in vec(i) each time. Also I don't really know how to differentiate between the elements of vec(i) and the whole vector itself vec_i. Any help is really appreciated. Thank you.
Best Answer