fclose(instrfind);
fclose(SERIAL);
SERIAL = serial('COM13','BaudRate',2400,'DataBits',8,'StopBits',1,'Timeout',.1); 
fopen(SERIAL);
old = ' ';
while(1)
    input = fscanf(SERIAL,'%c,%c,%c');
    if length(input) > 3
        data = input(1);
        A = input(2);
        DB = input(3);
        if ((data >= 'a') | (data <= 'z'))
            if data ~= old
                fid = fopen('E:/matlabtest/temp.txt','w')';
                fwrite(fid,data);
                fwrite(fid,A);
                fwrite(fid,DB);
                fclose(fid);
            else
                old = data;
            end
        end
    end
end