Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'll give this a shot based on the information you've provided. I don't have timing information though.</p> <ol> <li>Make <code>px</code> a 3D matrix <code>DxVxC</code> (instead of <code>1xC</code> cell array of <code>DxV</code> 2D matrices)</li> <li><code>px_new=px(:,x,:)</code> reorganizes the matrix, putting your values of interest into the main diagonal of the first two dimensions</li> <li>Create a logical index with ones on the diagonal (<code>mask=eye(D,D);</code>); repmat so it is the size of C in the third dimension.</li> <li>Index into <code>px_new</code> and <code>reshape</code>, so that there are <code>C</code> columns.</li> <li><code>prod</code> the columns, leaving a <code>1xC</code> vector</li> <li><p>Multiply this (element-wise) with <code>py</code> to get your output</p> <pre><code>px = nan(3,4,5); %# create test 3D matrix px(:, :, 1) = [1 2 3 4; 4 5 6 4; 7 8 9 4]; px(:,:,2)=px(:,:,1)*1.5; px(:,:,3)=px(:,:,2)*1.5; px(:,:,4)=px(:,:,3)*1.5; px(:,:,5)=px(:,:,4)*1.5; x = [4 2 3]; %# 1xD vector discrete on 1-V px_new=px(:,x,:); %# reorganize into DxDxC idx=logical(repmat(eye(size(pd_new,1))),[1,1,size(pd_new,3)])); %# logical index P = prod(reshape(pd_new(idx),[],size(pd_new,3))); %#P is now 1xC vector </code></pre></li> </ol> <p>This code was tested at <a href="http://www.online-utility.org/math/math_calculator.jsp" rel="nofollow">http://www.online-utility.org/math/math_calculator.jsp</a></p> <p>Edit: I was taking a couple of unnecessary steps originally. I've updated it to be more concise.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload