Hi,
I have a matrix 'a' and I want to index only certain rows and delete them. Refer to code below.
Logic : when I reach the row starting point A or starting point B, I want to delete the following rows which contain the value [1 2 4 5]. I need to delete only those which come below either starting point A or B, also, the number of times [1 2 4 5] repeat is not fixed. If you observe, even after the 11th row [1 2 3 7] there are values [1 2 4 5] present but I want to retain them.
Any suggestions would be of great help, thank you. 🙂
a = 1 2 3 4 % start point A
1 2 4 5 % delete
1 2 4 5 % delete 1 2 4 5 % delete 1 2 4 5 % delete 1 2 3 5 % don't delete
1 2 3 6 % start point B
1 2 4 5 % delete
1 2 4 5 % delete 1 2 3 5 % don't delete 1 2 3 7 % don't delete anything from below here.
1 2 4 5 1 2 4 5 1 2 4 5 1 2 4 5 1 2 3 5b = size(a,1);for c = 1:b if a(c, [1:4]) == [1, 2, 3, 4] | [1, 2, 3, 6] for d = c+1:b if (a(d, [1:4]) == [1, 2, 4, 5]) a(d, 5) = 1; end end end end% displaying the numbers except for the ones that have 1 in their last column, basically deleting the rows with 1 in their last column
z = a(:, end);y = a(~(z == 2), :);y(:, end) = []%% The result I'm obtaining from the above code :
y = 1 2 3 4 1 2 3 5 1 2 3 6 1 2 3 5 1 2 3 7 1 2 3 5%% My expected output :
y = 1 2 3 4 1 2 3 5 1 2 3 6 1 2 3 5 1 2 3 7 1 2 4 5 1 2 4 5 1 2 4 5 1 2 4 5 1 2 3 5
Best Answer