Created
April 10, 2014 20:38
-
-
Save tonyfast/10420967 to your computer and use it in GitHub Desktop.
Populate values in an N-D Matlab array from the indices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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