Hi Davneet,
I understand that you are trying to perform an exponential decay fit to your dataset using MATLAB's lsqcurvefit function. After updating your model to include an additional coefficient for the X2 term to better capture the features of your data, you encountered issues.
Based on the shared information, I find that the issue is the current use of AgVct with Expdecay_fit for plotting. The original Expdecay_fit function is designed to work with a two-column x input, where x(:,1) and x(:,2) correspond to X1 and X2 respectively. However, when plotting the fit, you are only providing AgVct (which seems to only represent a range of values for X1), but not any corresponding values for X2. This mismatch in expected input dimensions is likely why you're seeing unexpected output.
Here is a revised approach assuming you want to hold X2 constant at some average value for plotting (or you could adjust this to vary X2 as needed):
% Assuming you want to use an average value for X2 or any specific value for plotting
averageX2 = mean(xaxis(:,2));
% Now, create a 2-column matrix for plotting where the first column is AgVct (your X1 range)
% and the second column is the constant averageX2
AgVct2 = [linspace(min(xaxis(:,1)), max(xaxis(:,1)), 10000)', repmat(averageX2, 10000, 1)];
% Now when you call Expdecay_fit for plotting, use the new AgVct2 which includes both X1 and X2
GR_DecayFit = Expdecay_fit(GRfitvar, AgVct2);
% Plotting the original data
figure(1)
plot(xaxis(:,1), log(inputArg1), 'bp'); % Assuming you want to plot the log of inputArg1 to match the fit function's output
hold on;
% Plotting the fit - make sure to exponentiate the result if your original data isn't in log space
plot(AgVct2(:,1), exp(real(GR_DecayFit)), 'r');
This revision involves creating a 2-column matrix AgVct2 where the first column is your finely spaced X1 values (AgVct) and the second column is a constant value for X2 (here, I used the mean of your X2 values from xaxis, but you can adjust this to match your specific needs).
Hope this helps.
Regards,
Nipun