www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/FillOutputwithNaNValuesExample.m

    %% Fill Output with NaN Values  

%% 
% Create a vector of data, |val|, and a matrix of subscripts, |subs|. 
val = 101:106';
subs = [1 1; 2 2; 3 3; 1 1; 2 2; 4 4] 

%%
% The subscripts in |subs| define a 4-by-4 matrix for the output, but only
% reference 4 out of the 16 elements. By default, the other 12 elements
% are |0| in the output.  

%% 
% Use the |fillval| input of |accumarray| to fill in the extra output elements
% with NaN values. 
A = accumarray(subs,val,[],[],NaN) 

%%
% The result is a 4-by-4 matrix padded with NaN values.