0001 function z=nt_double2int(x,param)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 nt_greetings;
0028
0029
0030 if iscell(x)
0031 for iChunk=1:numel(x)
0032 z{iChunk}=nt_double2int(x{iChunk},param);
0033 end
0034 return
0035 end
0036
0037 if isfloat(x)
0038
0039 if nargin<2; param='int16'; end
0040 intsize=param;
0041 sz=size(x);
0042 if ndims(x)>2; x=x(:,:); end
0043
0044 z.ints=zeros(size(x),intsize);
0045 z.min=zeros(1,size(x,2));
0046 z.max=zeros(1,size(x,2));
0047 z.intsize=intsize;
0048
0049
0050 for iCol=1:size(x,2);
0051 z.min(iCol)=min(x(:,iCol));
0052 z.max(iCol)=max(x(:,iCol));
0053 z.ints(:,iCol)= double(intmin(intsize)) + ...
0054 (x(:,iCol) - z.min(iCol)) * ...
0055 ( double(intmax(intsize))-double(intmin(intsize)) ) /...
0056 ( z.max(iCol)-z.min(iCol) );
0057 end
0058 z.ints=reshape(z.ints,sz);
0059
0060 else
0061
0062 assert(isstruct(x), '!');
0063 intsize=x.intsize;
0064 sz=size(x.ints);
0065 if ndims(x.ints)>2; x.ints=x.ints(:,:); end
0066
0067 if nargin<2; param=[]; end
0068 indices=param;
0069
0070 if isempty(indices);
0071
0072
0073 z=zeros(size(x.ints));
0074 for iCol=1:size(x.ints,2)
0075 z(:,iCol) = x.min(iCol) + ...
0076 (x.max(iCol)-x.min(iCol)) / (double(intmax(intsize))-double(intmin(intsize))) * (double(x.ints(:,iCol))-double(intmin(intsize)));
0077 end
0078 z=reshape(z,sz);
0079
0080 else
0081
0082 if numel(indices)<2; indices{2}=[]; end
0083 if isempty(indices{1}); indices{1}=1:size(x.ints,1); end
0084 if isempty(indices{2}); indices{2}=1:size(x.ints,2); end
0085
0086 z=zeros(numel(indices{1}),numel(indices{2}));
0087
0088 for idx=1:numel(indices{2})
0089 iCol=indices{2}(idx);
0090 z(:,idx) = x.min(iCol) + ...
0091 (x.max(iCol)-x.min(iCol)) / (double ( double(intmax(intsize))-double(intmin(intsize)))) * (double(x.ints(indices{1},iCol))-double(intmin(intsize)));
0092 end
0093
0094
0095 if numel(sz)>2 && numel(indices{2})<size(x.ints,2)
0096 warning('output data has not been reshaped');
0097 else
0098 z=reshape(z,[numel(indices{1}),numel(indices{2})]);
0099 end
0100
0101 end
0102
0103 end
0104
0105
0106
0107
0108