In fact , I have a Matrix like X =

0 5.2 4.8 28.8

0 0 1.0 33.8

0 0 0 33.4

0 0 0 0

I would like to create like this

0 5.2 4.8 28.8

NaN 0 1.08 33.8

NaN NaN 0 33.4

NaN NaN NaN 0

I wrote something like this, but it does not work very well. because I would like to keep the first column and first row zero value, the second column second row zero value and so on

[m,n]=size (X) for i=1:m; for j=1:n; if X(i,j)==0 X(i,j)= NaN ; end end end

## Best Answer