MATLAB: How to remove numbers from a vector

loopvectors

I am using graphical data and looping round a set of data. So, how can I write an if statement to remove zeros from the start and end of the vector so that only the needed data is there, I dont want to remove all zeros though as the middle section of all the data sets has zeros which are needed?
The variable that the data sets loop through is called z_force

Best Answer

minidx = find(z_force, 1, 'first')
maxidx = find(z_force, 1, 'last')
z_force(minidx:maxidx)