MATLAB: From a matrix, remove a number from each row (in this case ” Inf ” )

matrix manipulationvectorization

Hello Matlab practitioner…I have a matrix a =
3 4 Inf 2
3 4 1 Inf
4 Inf 1 2
I want a matrix
b =
3 4 2
3 4 1
4 1 2
where each Inf in every row is removed. There is exactly one Inf in every row.
Thank you.

Best Answer

I tested it with an extra row:
A=[ 3 4 Inf 2
3 4 1 Inf
4 Inf 1 2
4 4 4 Inf];
temp_A=A';
temp_A(isinf(temp_A))=[];
A=reshape(temp_A,size(A,2)-1,size(A,1))';