Matlab programmingSolutionfunction outrows outcols findSe

Matlab programming

Solution

function [ outrows, outcols ] = findSeqFromMat( seq, mat )
    [ rows, cols ] = size(mat);
    outrows = [];
    outcols = [];
    tElems = size(seq,2);
    for r=1:rows
        for c=1:cols
            if mat(r,c) == seq(1)
                %look if complete sequence matches
                pushInAnswer= 0;
                %horizontally
                if c+ tElems-1 <= cols
                    pushInAnswer = 1;
                    for i=0:tElems-1
                        if mat(r,c+i) ~= seq(i+1)
                            pushInAnswer= 0;
                        end
                    end
                end
% remove comments, if vertical sequence is also to be detected
%                 if pushInAnswer == 0
%                     %try vertically
%                     if r+ tElems-1 <= rows
%                         pushInAnswer = 1;
%                         for i=0:tElems-1
%                             if mat(r+i,c) ~= seq(i+1)
%                                 pushInAnswer= 0;
%                             end
%                         end
%                     end
%                 end
                if pushInAnswer == 1
                    outrows = [outrows r];
                    outcols = [outcols c];
                end
            end
        end
    end
end

Matlab programmingSolutionfunction [ outrows, outcols ] = findSeqFromMat( seq, mat ) [ rows, cols ] = size(mat); outrows = []; outcols = []; tElems = size(seq,2

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site