MATLAB: To find a vector subset of a matrix in sequence ismember I have a vector A = [1 2 3] And another matrix B = [2 3 4 1; 1 2 3 4; 2 4 1 3; 2 3 1 4] I want to know which row of vector A is subset of Matrix B (in same sequence of A, i.e. 1 2 3 The answer is 2nd row of B matrix Best Answer Here is a solution in one line :A = [1 2 3];B = [2 3 4 1; 1 2 3 4; 2 4 1 3; 2 3 1 4];% Reshape B in a 1D array (all rows in a line)C = reshape(B', [1, numel(B)]);% Then use strfind to find a pattern in a string pattern within a string linear_index = strfind(C, A);% Compute the row number of the pattern knowing the initial number of columns row_number = ceil(linear_index/size(B, 2));% Or do it in a single line :row_number = ceil(strfind(reshape(B', [1, numel(B)]), A)/size(B, 2)); Related SolutionsMATLAB: From a=[1 2 3 4] to b=[1 1 2 2 3 3 4 4] b = repelem(a,2) MATLAB: Extract a double array to multiple arrays b1=aa(1:4:end);b2=aa(2:4:end);b3=aa(3:4:end);b4=aa(4:4:end); Related QuestionHow to multiply a vector 3 times to get a 3 dimentional matrixHow to change this matrix in this mannerHow to replace half the number of specific element in an arrayHow to genneral a repeat arrayIs there a better to multiply matrices with is patternHow to combine two cell arrays to corresponding elementsHOW CAN I PLOT THE FOLLOWING POINTS USING SURFACE PLOT
Best Answer