Calculate tangent-present on graph and in table

TorrO

Board Regular
Joined
Feb 13, 2003
Messages
118
Office Version
  1. 2013
Platform
  1. Windows
Hi

Case:
I have tried to make tangents based on pulse min/max per interval, I don't find the solution.
Also add tangent to graph is nothing I manage to understand.

Question:
Add tangents to a graph based on min and max values for each drag and brake, also add a table for tangent angles.


I have this graph, 33 minute workout, each second has a pulse reading.

1665294424988.png


Data
1665294558542.png


What I would like to present is a tangent with a angle, something like this:
1665294730994.png


And also make a table representing all intervals like this, data set you can download further down.

Inteval - tangent angle
number
1 30 deg
2 -84 deg
3 34 deg
4 -78 deg
....
21 40 deg -80 deg -> as many drags there is in workout data, presented in column J=Interval number

Data is here

Thanks up front
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Probably something can be done by working on the data serie values; if you can share a demo workbook with real data maybe we can work on it
 
Upvote 0
Probably something can be done by working on the data serie values; if you can share a demo workbook with real data maybe we can work on it

Hi

thanks for answer.
Sorry for late answer.
workbook here
 
Upvote 0
Something can be done, assuming that minimums and maximums follow each other with a regular rhythm; but the user need to provide few critical parametres, and the result should be checked to be sure that there aren't severe errors.

Let's use a User Function to get the coordinates of the peaks (min and max). I called it "SerieInfoTabl" and corresponds to the following code:
Code:
Function SerieInfoTabl(ByVal m1Point As Long, ByVal m2Point, ByVal ePoint As Long) As Variant
Dim aChart As Chart, yArea As String, mySplit
Dim PulseForm As String, SRSplit, oInd As Long
Dim oArr()
Dim MinY As Single, MinX As Long, MaxY As Single, MaxX As Long
'
Set aChart = ActiveSheet.ChartObjects(1).Chart
'
ReDim oArr(1 To 2, 0 To 4)
PulseForm = aChart.SeriesCollection("Pulse").Formula
mySplit = Split(PulseForm, ",", , vbTextCompare)
yArea = mySplit(UBound(mySplit) - 1)
oInd = 1
For j = 1 To 50
    span = (m2Point - m1Point)
    'Debug.Print span
    For i = 0 To 1
        If i = 0 Then bPoint = m1Point Else bPoint = m2Point
        SRSplit = Split(Replace(yArea, "'", "", , , vbTextCompare), "!", , vbTextCompare)
        MinY = Application.WorksheetFunction.Min(Sheets(SRSplit(0)).Range(SRSplit(1)).Cells(1, 1).Offset(bPoint - span / 4, 0).Resize(span / 2, 1))
        'Debug.Print "MinY = " & MinY, Sheets(SRSplit(0)).Range(SRSplit(1)).Cells(1, 1).Offset(bPoint - span / 4, 0).Resize(span / 2, 1).Address(0, 0); ""
        MinX = Application.Match(MinY, Sheets(SRSplit(0)).Range(SRSplit(1)).Cells(1, 1).Offset(bPoint - span / 4, 0).Resize(span / 2, 1), False) + bPoint - span / 4
        MaxY = Application.WorksheetFunction.Max(Sheets(SRSplit(0)).Range(SRSplit(1)).Cells(1, 1).Offset(bPoint + span / 6, 0).Resize(span / 2, 1))
        'Debug.Print "MaxY=" & MaxY, Sheets(SRSplit(0)).Range(SRSplit(1)).Cells(1, 1).Offset(bPoint + span / 6, 0).Resize(span / 2, 1).Address(0, 0)
        MaxX = Application.Match(MaxY, Sheets(SRSplit(0)).Range(SRSplit(1)).Cells(1, 1).Offset(bPoint + span / 6, 0).Resize(span / 2, 1), False) + bPoint + span / 6
        oArr(1, oInd + 0 + i * 2) = MinX: oArr(2, oInd + 0 + i * 2) = MinY: oArr(1, oInd + 1 + i * 2) = MaxX: oArr(2, oInd + 1 + i * 2) = MaxY
    Next i
    oInd = oInd + 4
    m1Point = MinX
    m2Point = m1Point + (MaxX - MinX) * 2
    If m2Point > ePoint Then Exit For
    ReDim Preserve oArr(1 To 2, 0 To UBound(oArr, 2) + 2)
    oInd = oInd - 2
Next j
oArr(1, 0) = j * 2 + 2
If Parent.Caller.Columns.Count > UBound(oArr, 2) Then
    ReDim Preserve oArr(1 To 2, 0 To Parent.Caller.Columns.Count)
ElseIf Parent.Caller.Columns.Count < UBound(oArr, 2) Then
    oArr(2, 0) = (UBound(oArr, 2) - Parent.Caller.Columns.Count) & "##"
End If
'Debug.Print "J=" & j
SerieInfoTabl = oArr
End Function
It requires 3 parametres:
-the X (horizontal) position of the first Minimum to consider
-the X position of the second Minimum
-the X position of the last Minimum to consider
(all these info can be provided with a certain level of tolerance)

Using the file you provided, I have noted the 3 highlighted coordinates (see first image): setting the mouse near the points I got the following X positions:
270; 463; 1750
I loaded these values in cells W20-W21-W22 (see the second image)

With these parametres we are ready to get the best guess of the peaks via the Function SerieInfoTabl, using in W23 the following formula:
Code:
=SerieInfoTabl(W20,W21,W22)
It is an array formula and need to be inserted into an area of 2 Rows * N Columns:
-Select W23:AP24 (I'll explain later how setting the area)
-Set the given formula into the Formula bar
-Confirm the formula using the combination Contr-Shift-Enter, not Enter alone

This should return a sequence or Paired cells (vertical paired) that contains the X (first row) and Y (second row) of the first Minimum; the X and the Y of the first Maximun; the X and the Y of the second Minimum; and so on until the latest X to consider (1750, set in W22, in my example)

See the second image (the yellow area are the 3 parametres; the blue area are the values returned by the formula)

The first column of the returned result contains "service information":
-the first Row specify how many nodes are returned by the function (18, in my example)
-the second Row contains either 0, if the formula has been entered in an area enough wide to contains all the results; or N## if the area is not wide enough, and N will state how many columns are missing. In this second hypotesis, if you want to extend the formula on additional columns:
-Select the current Area; extend the selection for as many columns you need; press F2 (edit formula), confirm using Contr-Shift-Enter

In case you set the formula in more columns than those that are necessary, 0 will be used to fill the unused columns

So now we have X1,Y1 of the first Minumum, X2,Y2 of the first Maximum
We can now calculate the "slope" of the line passing from the two pairs of coordinates using the formula
m = (Y2-Y1)/(X2-X1)
Translated to Excel: in X25 I used the formula
Code:
=(Y24-X24)/(Y23-X23)

Finally we can calculate the angle of this first line using
alpha = ATAN(slope)

Translated in Excel, with results in Degres, in X26 I used the formula
Code:
=DEGREES(ATAN(X25))

Now copy X25:X26 to the right for as many nodes you have

This is shown in the folllowing XL2BB minisheet
Cell Formulas
RangeFormula
W23:AP24W23=SerieInfoTabl(W20,W21,W22)
X25:AN25X25=(Y24-X24)/(Y23-X23)
X26:AN26X26=DEGREES(ATAN(X25))
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.


A couple of final notices:
-the function works by analyzing the source data of the serie named "Pulse" of graph #1 of the active sheet
-the users that have an Excel version that support Dynamic Array may insert the formula that uses SerieInfoTabl in a single cell and its results will expand for 2 rows * N columns (N as needed)

HTH...
 

Attachments

  • TORRO-1_Immagine 2022-11-01 004045.jpg
    TORRO-1_Immagine 2022-11-01 004045.jpg
    108.9 KB · Views: 5
  • TORRO-2_Immagine 2022-11-01 010743.jpg
    TORRO-2_Immagine 2022-11-01 010743.jpg
    51.7 KB · Views: 5
Upvote 0
Hi Anthony47

Thanks for your effort.
I will try to implement this code, it will take some time due to heavy work load.

You will hear more from me.

Thanks!
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,721
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top