The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

Advanced Search

Back to Topic List Back to Topic List  

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,:)';

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]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.