how to solve matrix?

1 visualización (últimos 30 días)
Ali Mukhtar
Ali Mukhtar el 19 de Sept. de 2019
Comentada: Guillaume el 21 de Sept. de 2019
if i have matrix M=[1 0 1; 0 0 1; 1 1 1] and T=5 apply a condition on this matrix
if nnz(M)>= T perform task
and make elseif nnz(M)< T should not leave this condition until i make all elements in nnz(M) matrix ==0 but im not able to hold in this condition

Respuestas (1)

Fabio Freschi
Fabio Freschi el 19 de Sept. de 2019
If I understand correctly if nnz(M)< T the matrix is the null matrix
M = [1 0 1; 0 0 1; 1 1 1];
T = 5;
if nnz(M)>= T
fprintf('My task\n')
else % not necessary: elseif nnz(M)< T
M(M ~= 0) = 0;
end
  11 comentarios
Walter Roberson
Walter Roberson el 21 de Sept. de 2019
w == 0.99
There might not be any locations in w that are bit-wise identical to the internal representation of 0.99, as 1/10 is not exactly representable in binary floating point, so 0.99 is not exactly representable. There is also round-off difficulties during calculations. You should rarely compare floating point numbers exactly to a literal number that is not an integer (and a good deal of the time, you should not compare exactly to an integer either.)
Guillaume
Guillaume el 21 de Sept. de 2019
Yes, I have purposefully ignored NaNs, empty and vectors in my statement above as the OP is clearly a beginner and nnz cannot return these.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by