i want to read only non zero numerical from the matrix
    3 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
a=[0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 0 0 0]
a(1,11:17)
then it will display
1 2 3 4 5 6 7
is there any code to read non zero numerical automatically
0 Kommentare
Akzeptierte Antwort
  David
      
 am 19 Jan. 2012
        To get the non-zero elements
a(a~=0)
Be careful with the comparison of floats/doubles (some zeros may just be very very small (if there are the result of a calculation) so it may be best to have a compare function:
tol = 1000*sqrt(eps);
cmpTol = @(x) abs(x)<tol;
and do something like
a(~cmpTol(a))
0 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
				Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


