Lookup values in a 6-D matrix using indices from columns of another matrix.

Trying to look for values in the v_tbl based on index provided by each column of quant_sysplus.
Problem: Runs too slow because I'm using two For loops. Is there a faster way of accessing the values?
v_tbl is a 6-D array that contains values of interest. quant_sysplus is 3-D (1:6,1000,3) array with each column containing a set of indices (1:6) to a value in v_tbl.
The following is what I have so far and it works, but there are a lot of states (121x121x24x7x7x3) that I have to step through. The two For Loops makes it extremely slow when I have 3000 sets of indices to lookup in each state.
for ind_page=1:page %page=3
for ind_col=1:Np %Np=1000 lookup(1,ind_col,ind_page)=v_tbl(quant_sysplus(1,ind_col,ind_page),quant_sysplus(2,ind_col,ind_page),quant_sysplus(3,ind_col,ind_page),quant_sysplus(4,ind_col,ind_page),quant_sysplus(5,ind_col,ind_page),quant_sysplus(6,ind_col,ind_page)); % Returns the values for each sample
end
end
I've tried Parfor as well, but was slower probably because the comm overhead was high.
Any suggestions?? Thank you.
David

4 Comments

Have you tried (no loops)
lookup(1,:,:)=v_tbl(quant_sysplus(1,:,:),quant_sysplus(2,:,:),quant_sysplus(3,:,:),quant_sysplus(4,:,:),quant_sysplus(5,:,:),quant_sysplus(6,:,:));
This was what I thought would work but causes dimension mismatch.
Can you attach your arrays? Just to see what's going on and test different solutions for speed.
v_tbl and quant_sysplus are attached. quant_sysplus has 30 samples (each row is a sample)(1:12,10,3). Rows 1:6 are the actual indices to be used on v_tbl. Can ignore rows 7:12 for now. v_tbl is populated with some values but most of it is still 0 because I haven't ran through all of the states. For now, Np will have to changed to 10 since there are only 10 columns per page (eventually Np=1000).
Thank you.

Sign in to comment.

 Accepted Answer

sz = size( v_tbl );
lookup = v_tbl( sub2ind( sz, quant_sysplus(1,:,:), quant_sysplus(2,:,:), quant_sysplus(3,:,:), quant_sysplus(4,:,:), quant_sysplus(5,:,:), quant_sysplus(6,:,:) ) );
should work I think.
You need to convert your multi-dimensional subscripts into 1d indices into the 6d array.

More Answers (0)

Asked:

on 31 Jul 2014

Commented:

on 31 Jul 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!