How can i calculate the difference between two points at various positions on a plot?

14 views (last 30 days)
Hello All, i am fairly new to the MATlab program and am tasked with evaluating some data for a school project. I have been able to successfully plot 3 curves that form a step response graph. What i have are 3 arrays containing thousands of values each.
- Torque, Actual Position & Desired Position
The Torque plot increases in steps of 100 up to 1600. What i need to do is whenever the data in the torque array changes by an absolute value of more than 99, set a flag and go forward 250 data points and analyze how close Actual Position and Desired Position are at those points. However i'm having trouble trying to understand what approach would be best. Any help is appreciated, thanks.

Answers (3)

Tom
Tom on 17 Jun 2013
You can use the UNIQUE function to find when the torque values change, (assuming they only stay the same or increase from one point to the next?)
[~,I] = unique(Torque,'first');
actPos(I+250) - desPos(I+250);

Barnabas
Barnabas on 17 Jun 2013
What are the ~ & I values representing? Sorry i'm still a bit new to the language, and can you specify by how much of a torque value change to look for?
  2 Comments
Tom
Tom on 17 Jun 2013
the ~ suppresses an output: I want the second output from UNIQUE, but I can't get the second without also requesting the first, so to ignore the first output ~ is used.
I is then the element number of the first of each of the different torque values. It doesn't look for a specific change in torque value: you said it increases by steps of 100, so this looks for the point at which each step occurs.
Try this as an example:
Torque = [0 0 0 0 100 100 100 200 200 200 200 200 200 300];
[~,I] = unique(Torque,'first');
I =
1 5 8 14
Barnabas
Barnabas on 17 Jun 2013
Thank you for your help, is there an easy way to set Torque equal to the Array as opposed to manually inputting the values in brackets?

Sign in to comment.


Barnabas
Barnabas on 18 Jun 2013
Edited: Barnabas on 18 Jun 2013
This function will work for one of my step response areas, however i have some files that have numerous torque ramps in different intervals at different sections. Is there a way to set the unique function to search for a change in the value, and go from the beginning of the array to the end?
For Instance, the vector will look something like this:
[ 0 100 0 200 0 300 0 400 0 25 0 50 0 75 0 100 0 125 0 150 0 75 ... ] etc...
With this type of data the unique function searches in incremental order and will give me an output of something like this:
[10 12 14 16 2 18 20 22 4 6 8]
I would need it to search in order from beginning to last on change to have an output of:
[ 2 4 6 8 10 12 14 16 18 20 22]
Thanks

Community Treasure Hunt

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

Start Hunting!