在单独的脚本中通过nlinfit进行索引仅返回一组适合的值

时间:2018-11-28 23:06:47

标签: matlab indexing

我正试图通过此函数传递I,V,H的三个cell2mat数组,并绘制下面来自nlinfit模型的参数结果。但是,当代码运行时,它什么也不做,只存储一个值。任何帮助表示赞赏:)

function [Icp] = Fraunhofer_Function(I,V,H)        

V1 = @(b,I)(b(1).*sign(I).*real(sqrt(I.^2 - (sign(I).*(   (b(2)+b(3)/2)  )).^2)) + b(4));
Vthresx = find(V<=1e-3 & V>=0);
Ithresvec = max(I(Vthresx));

Voffsetx = find(I<=0.1e-3 & I>=-.1e-3);
Voffset = max(V(Voffsetx));

Rn =  (max(V)-min(V))/(max(I)-min(I));

beta1 = [Rn; Ithresvec; -Ithresvec; Voffset]; %Init values  b1=Rn b2 = Icp, b3 = Icm, b4 = Voffset
opts = statset('MaxIter', 500000, 'MaxFunEvals', 100000, 'RobustWgtFun', 'andrews');
B1 = nlinfit(I, V, V1, beta1, opts ); %Fit 
Icp = V1(B1,V);


end



  files = dir('*.xlsx*');
  for k =1:length(files)
  filenames = files(k).name;

  txt = 'I,V,H';
  [num,txt,raw] = xlsread(filenames);

  %Put data into numerical columns
  Idata = num(:,1)'; Vdata = num(:,2)'; Hdata = num(:,3)';        
  [Hu,~,idx] = unique(Hdata);
  Isplit = splitapply(@(x) {x}, [Idata(:)],idx);
  Vsplit = splitapply(@(x) {x}, [Vdata(:)],idx);
  Hsplit = splitapply(@(x) {x}, [Hdata(:)],idx);    

  for l = 1:length(Isplit)

      I = (Isplit{l,1});
      V = (Vsplit{l,1});
      H = (Hsplit{l,1});

     %fit the data to the functional form
      Icp = Fraunhofer_Function(I,V,H);              

  end  

end

0 个答案:

没有答案