title: Nan return value when using the MATLAB function dll ed in C#
body: <p>I am using a MATLAB .dll ed function in my C# app.
  this function gonna process on 12 picture and then return a matrix. when I run it in matlab it works correctly, but when I call the .dll version in my C# app, returns a matrix assigned by NAN !
  However, when I give 7 or less picture to my app, the MATLAB function works. </p>
  
  <p>this is my matlab code:</p>
  
  <pre><code>function[result]= HDRMakerFunc(numExposures, Exposures, Lambda, numSamples, PicPath)
  imageList = dir(fullfile(PicPath,'*.jpg'));
  D=imageList;
  
  S = [D(:).datenum].'; 
  [S,S] = sort(S);
  S = {D(S).name};  % Cell array of names in order by datenum.
  
      weights = zeros(1,256);
      %make weight array
      for i=1:256
          weights(i) = weight(i,1,256);
      end
      % allocate resulting matrices
      zRed = zeros(numSamples, numExposures);
      zGreen = zeros(numSamples, numExposures);
      zBlue = zeros(numSamples, numExposures);
      %
      for i=1:numExposures
              % read the ith image
  %             temp =strcat( PicPath,'\', imageList(i).name);
              temp =strcat( PicPath,'\',S{1,i});
              img = imread(temp);
              numPixels = size(img,1) * size(img,2);
              step = numPixels / numSamples;
              sampleIndices = floor((1:step:numPixels));
              sampleIndices = sampleIndices';
              % sample the image for each color channel
              [zRedTemp, zGreenTemp, zBlueTemp] = sampel(img, sampleIndices);
              % build the resulting, small image consisting
              % of samples of the original image
              zRed(:,i) = zRedTemp;
              zGreen(:,i) = zGreenTemp;
              zBlue(:,i) = zBlueTemp;
      end
      % Creating exposures matrix B
      B = zeros(size(zRed,1)*size(zRed,2), numExposures);
      for i = 1:numExposures
          B(:,i) = reallog(Exposures(i));
      end
  
      % solve the system for each color channel
      % result[3][2]; % row = g col = lE  RGB
      % solve the system for each color channel
      [gRed,lERed]=gsolve(zRed, B, Lambda, weights);
      pause(5);
      [gGreen,lEGreen]=gsolve(zGreen, B, Lambda, weights);
      pause(5);
      [gBlue,lEBlue]=gsolve(zBlue, B, Lambda, weights);
      pause(5);
      result = {-gRed,lERed, -gGreen,lEGreen,-gBlue,lEBlue};
  
      y = (0:255);
      figure
      hold on
      subplot(2,2,1)
      plot(result{1},y, 'r-');
      xlabel('log Exposure X');
      ylabel('Pixel Value Z');
  
      subplot(2,2,2)
      plot( result{3},y, 'g');
      hold on
      % plot(gGreen, y, 'r*');
      xlabel('log Exposure X');
      ylabel('Pixel Value Z');
  
      subplot(2,2,3)
      plot( result{5},y , 'b-');
      xlabel('log Exposure X');
      ylabel('Pixel Value Z');
  
      figure
      y = (0:255);
      plot( result{1}, y );
      hold all
      plot( result{3} , y);
      fig = plot( result{5} ,y);
  
      save ('gResult','result');
  end
  </code></pre>
  
  <p>and also if the exposure times be high, it does not work :|</p>
  
  <p>I Compiled it with matlab coder, .NET assmebly type . is there any body to figure out why this problem occurs?!
  thanks.</p>