How to add some symbols into a matrix ?
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
Andrei Bobrov
el 30 de Ag. de 2011
X(tril(true(size(X)),-1))=nan
add
X(bsxfun(@lt,1:4,(1:4)'))=nan
more
only for cell array
Xc = num2cell(X)
Xc(bsxfun(@lt,1:4,(1:4)'))={'-'}
4 comentarios
Niki
el 30 de Ag. de 2011
Walter Roberson
el 30 de Ag. de 2011
text symbols cannot appear in numeric matrices. If you want a number prefixed by "-" then probably the easiest way to do that is to multiply the number by negative 1. But it looks to me like perhaps you want an n-dash rather than a minus sign.
Andrei Bobrov
el 30 de Ag. de 2011
I agree with Walter Robenson
Niki
el 30 de Ag. de 2011
Categorías
Más información sobre Numbers and Precision en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!