Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Ross
Posts:
4
Registered:
7/9/13


MultiDimensional Array Creation using rows of a 2d Matrix
Posted:
Jul 16, 2013 5:40 PM


Here is the code I am trying to get faster (eliminating the for loop):
dist_mat_new = zeros([ length(lx) 97 97 32 ]); size(distance_prime_new) = length(lx) 301088 % 301088 = 97*97*32 size(linear_index) = 301088
for k = 1:length(lx) dist_mat_new(k,linear_index) = distance_prime_new(k,:)'; end
so to clarify, linear_index is a vector that contains all the linear indices of a 97x97x32 array. What I am trying to do is to put each row of distance_prime_new into dist_mat_new, where dist_mat_new(1,:,:,:) will be filled with the first row of distance_prime_new. The linear index of the elements in distance_prime_new is given by the value in linear_index at the column of distance_prime_new, i.e. the linear_index for all values at distance_prime_new(:,234) is found at linear_index(234).
Just want to use a better commmand as opposed to a for loop.



