Doug Hull, MathWorks
(Originally postedon Doug's MATLAB Video Tutorials blog.)
The MATLAB user has this:
clear clc M(:,:,1) = [1,2;3,4]; M(:,:,2) = [21,22;23,24]; J = [1,2; 2,1];
They want this:
ans = [1 22 23 4]
They tried this:
D = M(:,:,J) % This doesn't work,
This video discusses this solution:
[nR, nC] = size(J); D = zeros(nR,nC); for r = 1:nR for c = 1:nC D(r,c) = M(r,c,J(r,c)); end end
Recorded: 9 Dec 2008
Featured Product
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
Selectweb siteYou can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.