Skip to content

Instantly share code, notes, and snippets.

@tonyfast
Created April 10, 2014 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonyfast/10420967 to your computer and use it in GitHub Desktop.
Save tonyfast/10420967 to your computer and use it in GitHub Desktop.
Populate values in an N-D Matlab array from the indices
sz = [ 10 10 10 3];
N = prod(sz);
% Indices into elements - Absolute indices
uid = unique( round(N*rand(100,1)));
% Values of the elements
values = rand(numel(uid),1);
A = zeros( sz );
A(uid) = values;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment