I have a code that reads data in a set of files and does some plots and fits on the data. The code I have at the moment is:
D = uigetdircd(D);S = dir(fullfile(D,'LIV Data T= *.mat')); % Makes a structure with all files
N = numel(S); % Counts number of files
CM = cool(N); % set colormap
fig1 = figure;for ii = 1:N T = load(fullfile(D,S(ii).name)); % Load each file as a structure
I = T.num(3:end,1); % Extract each parameter from full file and ignore first two data points - they're often dodgy
V = T.num(3:end,2); P = T.num(3:end,3); DataPoints = length(I); thresh = find(P>LasingThreshold,1); % checks for when power is above threshold for fitting
fit = polyfit(I(thresh:round(DataPoints/3)),P(thresh:round(DataPoints/3)),1); %Need value of P to be greater than the laser threshold - this should be done better eventually
fitplot = polyval(fit, I); % evaluates fit as line
subplot(1,2,1); plot(I,P,'.','markers',5,'color',CM(ii,:)) plot(I,fitplot,'-.','color',CM(ii,:)) xlabel('Current (mA)') ylabel('Power (mW)') hold on subplot(1,2,2); plot(I,V,'.-','markers',4,'color',CM(ii,:)) xlabel('Current (mA)') ylabel('Voltage (V)') hold onend
This mostly works, however, the data points from the current power plot in the first loop are missing. The fit is still shown and in all of the following loops both the fit and the data points are on the graph. What is the problem with plotting the data points in the first loop?
Best Answer