Need help alternating a code
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
Hi, I had... a = [ 2 5 1; 3 6 2; 3 4 1; 9 4 2; 8 3 1; 3 2 2; 9 5 2; 4 8 1]
Notice how the last column follows a pattern of 1, 2,1,2..and so on. The 7th row however has a 2 in the last column just like the 6th row before...thus does not follow the pattern. The code below deletes the 7th row.
 [m,n] = size(orderedheelstrikes);
 expected = orderedheelstrikes (1,n); % initialize expected value in 1st row
 x = false(m,1); % initialize the deletion flag array
 for k=1:m
    if( orderedheelstrikes(k,n) ~= expected )
        x(k-1) = true; % if not as expected, mark for deletion
    else
        expected = 3 - expected; % if as expected, update expected
    end
 end
 orderedheelstrikes(x,:) = []; % delete the unexpected pattern rows
Now I have changed some of my values and the last row follows a pattern of 3,4,3,4,3...etc. I was just wondering what I need to change in this code to accommodate for the new pattern. I want the code to do the same thing as before in terms of deleting in the example below the 7th row because the 4 is repeated.
Ex: a = [ 2 5 3; 3 6 4; 3 4 3; 9 4 4; 8 3 3; 3 2 4; 9 5 4; 4 8 3]
Thanks!
0 comentarios
Respuestas (1)
  Sean de Wolski
      
      
 el 29 de Jul. de 2015
        expected = [3; 4];
badrow = find(~bsxfun(@eq,reshape(a(:,end),2,[]),expected),1,'first')
If you're doing this row by row the above should work
0 comentarios
Ver también
Categorías
				Más información sobre Whos en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

