Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Multi-Dimensional Array Creation using rows of a 2-d Matrix
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Ross

Posts: 4
Registered: 7/9/13
Multi-Dimensional Array Creation using rows of a 2-d Matrix
Posted: Jul 16, 2013 5:40 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.