Matlab programming Edit This function takes 2 inputs seq mat
Matlab programming
Edit: This function takes 2 inputs: seq, mat. Seq is a sequence we want to find in the given matrix, mat. The function returns row and columns of all matching sequences. If there are multiple matches, the function will return a vector containing all positions. For this question the reading is done vertically.
Solution
Code:
findSeqFromMatVect.m file
function [outrows, outcols] = findSeqFromMatVect(seq,mat)
 outrows = [];
 outcols = [];
 for x = 1:size(mat,1)-size(seq,1)+1
 for y = 1:size(mat,2)-size(seq,2)+1
 %creating a block to check for the existance of sequence in the
 %given matrix
 block = mat(x:x+size(seq,1)-1,y:y+size(seq,2)-1);
 if isequal(seq,block)
 outrows(end+1) = x;
 outcols(end+1) = y;
 end
 end
 end
 end
test.m file:
seq = [1,2,3,4];
 mat = [9,1,2,3,4,8,5;
 1,2,3,4,8,5,6;
 2,8,7,1,2,3,4];
 [rows, cols]=findSeqFromMatVect(seq,mat)
output:
rows =
1 2 3
 cols =
2 1 4

