indexing through nlinfit in a seperate script only returns one fitted set of values












0















I am trying to pass three cell2mat arrays for I,V,H through this function and plot the result of the parameter from the nlinfit model below. But when the code is run it plots nothing and only stores one value. Any help is appreciated:)



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









share|improve this question



























    0















    I am trying to pass three cell2mat arrays for I,V,H through this function and plot the result of the parameter from the nlinfit model below. But when the code is run it plots nothing and only stores one value. Any help is appreciated:)



    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









    share|improve this question

























      0












      0








      0








      I am trying to pass three cell2mat arrays for I,V,H through this function and plot the result of the parameter from the nlinfit model below. But when the code is run it plots nothing and only stores one value. Any help is appreciated:)



      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









      share|improve this question














      I am trying to pass three cell2mat arrays for I,V,H through this function and plot the result of the parameter from the nlinfit model below. But when the code is run it plots nothing and only stores one value. Any help is appreciated:)



      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






      matlab indexing






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 28 '18 at 23:06









      Tyler RamTyler Ram

      85




      85
























          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53529460%2findexing-through-nlinfit-in-a-seperate-script-only-returns-one-fitted-set-of-val%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53529460%2findexing-through-nlinfit-in-a-seperate-script-only-returns-one-fitted-set-of-val%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Lallio

          Futebolista

          Jornalista