필터 지우기
필터 지우기

Code section clarification - function

조회 수: 12 (최근 30일)
Thor
Thor 2021년 2월 15일
편집: Thor 2021년 5월 14일
Hi everyone,
I am quite new to matlab, but I have some background knowlege in python and java.
I have been given this code to analyse and i am struggling to understand section 3 and 4. If anyone could tell me what those section do, i would greatly appreciate it.
This code is for analysing UV-VIS data ( x,y) = ( wavelenght , absorption) for a region between 400 - 800 nm. I believe section 3 doesnt need "for" and "end "syntax.
Many thanks for your help
function Analyse_UV( ConcnVector )
% Analyse_UV
% Function loads UV/Vis data, finds SPR band, fits model gaussian
% function to it using an evolutionary algorithm, and prepares the data
% for calculation of fwhm.
%% USER INPUTS
% 1) Save the csv file containing the UV/Vis data as 'data.csv'.
% 2) Create a vector (ConcnVector) e.g. [1 2 3 4 ...] containing the
% concentration values of the titrate (in uM).
% 3) If last dataset is of purified nanoparticles, the code reports the
% new NP concentration based on the input argument 'NPConc'.
% 3) Label the titrate for 'xlabel' in Section 8
close all
clc
%% NP CONCENTRATION
NPConc = 20;
%% 1) Import data file, and sort into headings and data
[NUM,TXT,NAW] = xlsread('Test1.xls');
ConcnVector = ConcnVector';
for i=1:1:length(ConcnVector);
legend2{i}=num2str(ConcnVector(i))';
end
%% 2) Acquire Dimensions & Resize
dim=size(NUM);
imax=(dim(1,2));
%% 3) Import Headings
for
i=1:2:imax
headings0(i)=[TXT(1,i)];
end
headings=headings0';
headings(cellfun(@isempty,headings))=[]; % delete empty entries
%% 4) Normalise Spectra to First Measurement
% Algorithm assumes first measurement is AuNPs. It then normalises all
% measurements to this measurement.
NcolNUM = size(NUM,2);
if NcolNUM >2
NUM2 = zeros(size(NUM,1),size(NUM,2));
LOWER = NUM(1,2);
for i=1:2:imax
UPPER = NUM(1,i+1);
NUM2(:,i+1) = NUM(:,i+1)-(UPPER-LOWER);
NUM2(:,i) = NUM(:,i);
end
end
NUM = NUM2;
%% 5) Run UV/Vis Analysis
SetSize = 0.5*size(NUM,2);
Results = zeros(SetSize,3); % zeros returns a 0 values array boxes
PlotNum = ceil(SetSize*0.5);
Set = 1;
figure;
hold all
for i=1:2:imax
y = NUM(:,i:i+1);
[SPR, FWHM, lmerr, xdataf, ydataf,SPRBandf] = Average_UV_13nm(y);
Results(((i+1)/2),1) = SPR;
Results(((i+1)/2),2) = FWHM;
Results(((i+1)/2),3) = lmerr;
subplot(2,PlotNum,Set);
plot(xdataf,ydataf,'-','linewidth',1.5);
hold on
plot(xdataf,SPRBandf,'--','linewidth',1.5);
title(headings((i+1)*0.5), 'FontSize',12);
xlim([450 620])
Set = Set+1;
j = (i+1)/2;
Abs(j) = max(SPRBandf);
if i == imax-3
IniAbs = max(SPRBandf); %Report SPR height before purification
end
if i == imax-1
FinAbs = max(SPRBandf); %Report SPR height after purification
end
xlim([400 650]);
end
%
% ConcRatio = FinAbs/IniAbs;
% New_Concentration_in_nM = ConcRatio*NPConc %Calculate new NP conc in nM
% DilutionCalc=(New_Concentration_in_nM, 0.5, 3000)
% hold off
%% 6) Sample Data Plot
%Plots last studied dataset & SPR fit
figure;
plot(xdataf,ydataf,'-','linewidth',1.5);
hold on
plot(xdataf,SPRBandf,'--','linewidth',2);
title('Example of UV/Vis Data with SPR Fit', 'FontSize',18);
xlabel('\lambda /nm', 'FontSize',16);
ylabel('Absorbance', 'FontSize',16);
% LEG=legend('UV/Vis Data','Levenberg-Marquandt fitting of SPR band');
SampleHeadings = {'UV/Vis Data','Levenberg-Marquandt fitting of SPR band'};
legend(SampleHeadings,'FontSize',16,'Location','NorthEast');
set(gca,'FontSize',13)
%LEG = findobj(AX,'type','text');
%set(LEG,'FontSize',14)
%% 7) Plot all UV/Vis Data
% N. B> - Title graph below
L = length(NUM);
figure;
for i=2:2:imax
hold all;
axis([400 800 0 2.2]) % Axis Lengths
plot(double(NUM(1:L,1)),double(NUM(1:L,i)),'linewidth',2);
set(gca, 'XTick', 0:50:800, 'FontSize',12);
end
Last = NUM(:,end);
JJJ = max(Last(1:350))*1.2;
axis([400 800 0 JJJ]) % Axis Lengths
legend(headings,'FontSize',13,'Location','SouthWest');
title('UV/Vis Absorption of Au^1^3NPs', 'FontSize',18); % More appropriate title required
xlabel('\lambda /nm', 'FontSize',20);
ylabel('Absorbance', 'FontSize',20);
figure;
uitable('Data', Results, 'ColumnName', {'SPR', 'FWHM', 'lmerr'},'RowName', headings,'Position', [20 20 1000 400]);
%% 8) Plot SPR & FWHM Data
SPR = Results(:,1);
SPR = SPR(:,1)-SPR(1,1);
FWHM = abs(Results(:,2));
FWHM = FWHM(:,1)-FWHM(1,1);
figure;
plot(ConcnVector,SPR,'--o','linewidth',2,'markers',9);
hold on
plot(ConcnVector,FWHM,'--*','linewidth',2,'markers',9);
axis auto
set(gca,'FontSize',13)
xlim([ConcnVector(1),ConcnVector(end)+1]);
ylim([0,SPR(end)+2]);
xlabel('Concentration of pHLIP/ \muM', 'FontSize',18); %% User Input Required %%
ylabel('\Delta\lambda /nm', 'FontSize',18);
SPR_Headings = {'Surface Plasmon Resonance \lambda_m_a_x','Full Width at Half Maximum'};
legend(SPR_Headings,'FontSize',13,'Location','NorthEast');
figure;
MaxAbs = max(Abs)*1.2;
MinAbs = min(Abs)*0.8;
[haxes,hline1,hline2] = plotyy(ConcnVector,SPR,ConcnVector,Abs);
set(hline1,'linewidth',1.5);
set(hline2,'linewidth',1.5);
set(haxes(2),'YLim',[MinAbs MaxAbs]); %MinAbs MaxAbs %adjust axes here!!!
set(haxes(2), 'YTick', MinAbs:0.2:MaxAbs, 'FontSize',13); %adjust axes here!!!
set(haxes(1),'YLim',[0 SPR(end)+2]);
set(haxes(1), 'YTick', 0:1:SPR(end)+4, 'FontSize',13);
ylabel(haxes(1),'\Delta\lambda /nm', 'FontSize',18); % left y-axis
ylabel(haxes(2),'Absorbance', 'FontSize',18) % right y-axis
xlim([ConcnVector(1),ConcnVector(end)+1]);
set(hline1,'Marker','o','MarkerSize',9);
set(hline1,'LineStyle','--');
set(hline2,'Marker','+','MarkerSize',9);
set(hline2,'LineStyle','--');
hold on
hline3 = plot(ConcnVector,FWHM,'-');
set(hline3,'linewidth',1.5);
set(hline3,'Marker','*','MarkerSize',9);
set(hline3,'LineStyle','--');
SPR_Headings2 = {'Surface Plasmon Resonance \lambda_m_a_x','Full Width at Half Maximum','Absorption'};
legend(SPR_Headings2,'FontSize',13,'Location','NorthWest');
xlabel('Concentration of EuL /\muM','FontSize',18);
set(haxes(2),'XLim',[ConcnVector(1),ConcnVector(end)+0.1]);
%
set(haxes(1),'XLim',[ConcnVector(1),ConcnVector(end)+0.1]);
set(haxes(2),'XTick',[]) % Remove ticks of axis 2 (leaves right-hand ticks of axis 1)
set(haxes(1),'Box','off')
set(haxes(1),'FontSize',14);
xlim([ConcnVector(1),ConcnVector(end)+0.1]);
end

답변 (1개)

Walter Roberson
Walter Roberson 2021년 2월 15일
for
i=1:2:imax
headings0(i)=[TXT(1,i)];
end
The for should be the same line as the i=
You are correct that a loop is not necessary
headings0(1:2:imax) = TXT(1,1:2:imax);
Every second heading is being copied.

카테고리

Help CenterFile Exchange에서 Data Preprocessing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by