MATLAB: How to extract the value of specified rows and columns of a bigger matrix to a smaller one

matrix manipulation

Dear madam/sir, I have two matrices, h and d. Both of them are 4*4. My purpose is to find the zero-columns of h, then create a matrix with the size of my answers. After that, substitute the values of matrix d in it. To illustrate what I have meant:
d=[0 10 11 12;
10 0 13 14;
11 13 0 15;
12 14 15 0]
h=[0 0.1 0 0.5;
0 0.2 0 0.6;
0 0.3 0 0.7;
0 0.4 0 0.8]
Here, the first and fourth columns of h are zero({1,4}). Create a 2*2 matrix and then put [d11 d14; d41 d44] in new matrix.

Best Answer

J=~any(h,1); %find zero-columns
newmatrix=d(J,J), %extract