Home > vbmeg > functions > common > utility > vb_cell_merge.m

vb_cell_merge

PURPOSE ^

merge cell array into vector

SYNOPSIS ^

function [xarray , Ndata] = vb_cell_merge(xcell, nid)

DESCRIPTION ^

 merge cell array into vector
  [xarray , Ndata] = vb_cell_merge(xcell)
 --- Input
 xcell : cell array
 ---Output
 xarray : concatenated data vector
 Ndata(n) : number of data in xcell{n}

 M. Sato 2006-7-21

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function    [xarray , Ndata] = vb_cell_merge(xcell, nid)
0002 % merge cell array into vector
0003 %  [xarray , Ndata] = vb_cell_merge(xcell)
0004 % --- Input
0005 % xcell : cell array
0006 % ---Output
0007 % xarray : concatenated data vector
0008 % Ndata(n) : number of data in xcell{n}
0009 %
0010 % M. Sato 2006-7-21
0011 %
0012 % Copyright (C) 2011, ATR All Rights Reserved.
0013 % License : New BSD License(see VBMEG_LICENSE.txt)
0014 
0015 N = length(xcell);
0016 
0017 if nargin < 2, nid = 1:N;end
0018 nid = nid(:)';
0019 
0020 N = length(nid);
0021 
0022 Ndata = zeros(N,1);
0023 
0024 for n=nid
0025     Ndata(n) = length(xcell{n});
0026 end
0027 
0028 xarray = zeros(sum(Ndata),1);
0029 
0030 next = 0;
0031 
0032 for n=nid
0033     xdata = xcell{n};
0034     n1 = next + 1;
0035     n2 = next + Ndata(n);
0036     xarray(n1:n2) = xdata(:);
0037     next = n2;
0038 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005