three level indexing and nested if statements
Mostrar comentarios más antiguos
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
1 comentario
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Downloads en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!