MATLAB: Three level indexing and nested if statements

if statementindexing

I have an index with three conditions, one condition in each column. I want to create a master index with one column for classifications which incorporate all three columns of the previous index. I did this successfully with two conditions but can't figure out how to add the third. I include the code that works and my attempt to change it.
for i = 1:length(DEFcomboIDX)
if DEFcomboIDX(i,1) % Type 1 SN %If comboIDX column 1 = 1 then Type 1

if ~DEFcomboIDX(i,2) % If comboIDX column 2 =0 then SN

DEFindex(i,1) = 1; % mark it with a 1

elseif DEFcomboIDX(i,2) % Type 1 VTA

DEFindex(i,1) = 2; % if comboIDX column 2 = 1 then VTa; Mark with a 2

end
elseif ~DEFcomboIDX(i,1) % Type 2 SN

if ~DEFcomboIDX(i,2)
DEFindex(i,1) = 3;
elseif DEFcomboIDX(i,2) % Type 2 VTA

DEFindex(i,1) = 4;
end
end
end
and what i'm trying now:
for i = 1:length(DEFcomboIDX)
if DEFcomboIDX(i,1) % Type 1 SN %If comboIDX column 1 = 1 then Type 1
if ~DEFcomboIDX(i,2) % If comboIDX column 2 =0 then SN
if DEFcomboIDX(i,3)
DEFindex(i,1) = 1; % mark it with a 1
elseif DEFcomboIDX(i,2) % Type 1 VTA
if DEFcomboIDX(i,3)
DEFindex(i,1) = 2; % if comboIDX column 2 = 1 then VTa; Mark with a 2
end
elseif ~DEFcomboIDX(i,1) % Type 2 SN
if ~DEFcomboIDX(i,2)
if DEFindex(i,1) = 3;
elseif DEFcomboIDX(i,2) % Type 2 VTA
DEFindex(i,1) = 4;
end
end
end
end
end
end

Best Answer

In your first code, the elseif for Type 2 SN is matched with the if for Type 1 SN . In your second code, the elseif for Type 2 SN is matched with the if for Type 1 VTA. I think you are missing an "end"