function type_pos = get_type_pos(array1, array2, typename1, typename2)
%Author:shizhixin
%Email:szhixin@gmail.com
%Blog:http://blog.youkuaiyun.com/shizhixin
%Date:2012-02-29
%function:从并排的两列数组中找到typename1或者为typename2的行号,并去重复
%Note:array1和array2的维数必须一致,否则type_pos返回0
%example:
% array1 = {'SL';'SL';'G'; 'SL'; 'GAL'; 'SL';}
% array2 ={'G';'-';'-';'-';'-';'-';}
% typename1 = 'G'
% typename2='GAL'
% type_pos = get_type_pos(array1, array2, typename1, typename2)%type_pos =1 3 5
% typename1 = 'G'
% typename2='G'
% type_pos = get_type_pos(array1, array2, typename1, typename2)%type_pos =1 3
if length(array1)~=length(array2)
disp 'error! array1 and array2 must be the same dim!'
type_pos = 0;
return
end
pos_11 = find_str_pos(array1, typename1);
pos_12 = find_str_pos(array1, typename2);
pos_21 = find_str_pos(array2, typename1);
pos_22 = find_str_pos(array2, typename2);
type_pos = unique([pos_11 pos_12 pos_21 pos_22]);%去掉重复值
end
%----------------------------------------------------
function str_pos = find_str_pos(array_cell, str)
%从一维CELL数组array_cell中找到指定str的位置
%array_cell={'SL';'G';'SL';'-';'GL';}
% pos = find_str_pos(array_cell, 'G')% pos = 2
str_pos = [];
len = length(array_cell);
for i=1:len
tempstr = array_cell{i};
if strcmp(tempstr, str)
str_pos = [str_pos i];
end
end
end