matlab - Get the indices along each dimension of a 3D matrix -


is there neater way indices along each dimension of 3d matrix? solution, don't repeating , taking 3 lines.

rows   = 1:size(vol,1); cols   = 1:size(vol,2); slices = 1:size(vol,3); 

you have various options, it's not simpler have.

% example volumen vol = flow(10);  % option 1 [rows cols slices] = deal( 1:size(vol,1), 1:size(vol,2), 1:size(vol,2) )  % option 2 indexvectors = cellfun( @(x) 1:size(vol,x), num2cell(1:3), 'uni',0 )  % option 3 indexvectors = arrayfun( @(x) {1:size(vol,x)}, 1:3) indexvectors = arrayfun( @(x) {1:x}, size(vol) ) 

the first returns 3 single vectors , latter 2 options return cell array vector each dimension in each cell.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -