close all; clear all; clc; dataFolder = 'c:\Tan2.xlsx'; excelObj = actxserver('Excel.Application'); excelWorkbook = excelObj.workbooks.Open(dataFolder); worksheets = excelObj.sheets; numSheets = worksheets.Count; for i=1:numSheets data =readtable(dataFolder, 'Sheet', i); sheet = get(worksheets,'item',i); disp(['Sheet',num2str(i), ' : ', sheet.Name]); V = data.V(~isnan(data.V)); %t I = data.I(~isnan(data.I)); %y %I = T1.I ; %V = T1.V ; dI = gradient(I ); dV = gradient(V); Vi = 1.3; % Choose Voltage Value To Calculate Slope Ii = interp1(V, I, Vi ); dVi = interp1(V, dV, Vi ) dIi = interp1(V, dI, Vi) Slope = dIi/dVi YIntercept = Ii - Slope * Vi XIntercept = -YIntercept / Slope figure plot(V,I ) hold on plot(Vi, Ii, 'p ') plot(xlim, xlim*Slope+YIntercept, '-r ') plot(XIntercept, 0, 'sr ') hold off grid xlabel('V ') ylabel('I ') text(Vi, Ii, sprintf('$I = %.3f \\times V %+.3f \\rightarrow \\ $', Slope, YIntercept), 'Horiz','right', 'Vert','middle', 'Interpreter','latex ') text(XIntercept, 0, sprintf('$%.4f V \\downarrow $', XIntercept), 'Horiz','right', 'Vert','bottom', 'Interpreter','latex ') ylim([0 max(ylim)]) end