MATLAB: How to remove certain rows and columns in a matrix

arrays

I have this 8×8 matrix and I want to preserve only the 1, 2, 7 and 8 (for now, these numbers change based on a computation) rows and column to get a 4×4 output matrix. How can I delete other columns and rows or copy the forementioned rows and columns to a new matrix with a new 4×4 structure?
Keep in mind that the desired rows and columns change based on a function computation.
A = [
0 1 0 0 0 0 0 1
1 0 0 0 0 0 1 0
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0
0 1 0 0 0 0 0 1
1 0 0 0 0 0 1 0 ]
Desired output (for this context):
A = [
0 1 0 1
1 0 1 0
0 1 0 1
1 0 1 0 ]

Best Answer

w = A([1,2,7,8], :)
Wanted = w(:, [1,2,7,8])