find the first and last nonzero element of an array

Asked by Tiger about 11 hours ago
Latest activity Answered by Jan Simon about 11 hours ago

exmple

a=[0,0,1,2,3,4,0,0]

which gives me positition 3, value 1 and position 6, value 4

Thanks!!

0 Comments

Tiger

Products

No products are associated with this question.

1 Answer

Answer by Jan Simon about 11 hours ago

Is this a homework question?

You are looking for a method to find the first and last element different from zero. Fortunately Matlab's find command can solve this directly. Therefore I assume, you did not search in the documentation already. While reading the Getting Started chapters is a good idea in general, you could search directly also:

docsearch find

Or ask Google about "Matlab find first non-zero".

0 Comments

Jan Simon

Contact us