如何在循环中分配对象

时间:2012-10-20 20:27:30

标签: matlab for-loop

Matlab代码:

% Performs Inner Filter Calculation using the UV absorbance spectrum.
ex_abs=absint(exabsstart:exinc:exabsend,:);
em_abs=absint(emabsstart:eminc:emabsend,:);
for i=1:length(em_abs)
    for j=1:(length(ex_abs))
        IFC(i,j)=ex_abs(j)+em_abs(i);
    end
end
Aci = A.*10.^(0.5*IFC); %This is the IFC.  
Warning: Integer operands are required for colon operator when used as index 
Undefined function or variable 'IFC'.
for循环中未定义

IFC,代码在Aci =语句处停止(因为IFC未定义)。有没有办法在循环中定义IFC

1 个答案:

答案 0 :(得分:3)

您应该在循环之前添加以下初始化:

 IFC=zeros(length(em_abs),length(ex_abs));