How would one go about trimming a matrix graphically?

4 views (last 30 days)
I have multiple large datasets (doesn't everyone) that I need to figure out a quicker way of "trimming" before post processing. I need to keep the original dataset unaltered, but each of these datasets has a variable that was changed multiple times during the recording. Each dataset has the first column being time and then another twenty or so columns of sensor data. For each of these datasets, I would like to quickly plot a single column of data versus time, select a timeframe of data that has reached steady state and then save the "trimmed" dataset as a new matrix.

Accepted Answer

Renee Coetsee
Renee Coetsee on 23 Mar 2017
You could accomplish this using the 'KeyPressFcn' figure callback:
When you click on the figure, you can plot a vertical line at that location. The x value of that line (which can be accessed from the line's properties) will correspond to the last (or first) value that you would like in the data matrix. You could use a button, which when pressed, will 1) duplicate the matrix, as to not modify the original 2) find the first occurrence x-value in the matrix 3) delete all elements after that x-value.
I hope these steps will help! Depending on your data, the first occurrence of an x-value may be before you want to trim. In this case, you can try finding the approximate index of the line using the line's position relative to the length of the axes.
  1 Comment
Richard Wanat
Richard Wanat on 25 May 2017
Sorry for the delay. I was not familiar with KeyPressFCN, but this did spawn an idea. Using GUIDE, I made a simple data input GUI that plotted multiple variables that may have changed during the logging (I had four being plotted at a time). Using the GUI, I could manually enter the location of two vertical bars (cursors) to "trim" between. I would have preferred to graphically drag the bars, but hey, it worked.
Unfortunately, there is too much IP in the code to post, but the one critical thing I needed to do was pass variables through global variables (filename, suffix, cursor locations, etc.).

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!