How to create your own X-Y data point tracker for a plot trace in Mathcad Prime 10
Mathcad Prime 10 has now been out in the wild for a few months and many users are appreciating the new features such as the advanced controls which offer a wide range of new possibilities.
My name is Johan Wikblad and have vast experience working as technical specialist and certified instructor at MathCAD 15 and MathCAD Prime. Personally, and so far, I have mostly adopted the advanced controls to enhance the visualization experience when it comes to highlight various kinds of results that can be represented in various plots.
Some examples of possibilities are quasi-static plot animations using the slider control, toggle on and off various plot traces using the check boxes control and the ability to choose color for a plot trace using the radio button controls are just some of the things that can be utilized by using the advanced controls.
In this blog post I would like to show you one of the ways where you can create a kind of “X-Y data point tracker functionality” for data tracking X- and Y-values in a one or several plot traces by using the advanced slide controller.
If you are a Mathcad user that has been working a lot with the legacy Mathcad, you are familiar with that this data tracking/plot tracing functionality already exists directly in the toolbox set for plotting. By just using your mouse pointer you could quickly hover over the area of interest to track the specific data points that you need. Here is an example what that functionality typically looked like in the legacy Mathcad:
While this plot tracing toolbox does not yet exist in Prime, the functionality can, at its core, be recreated using advanced controls. With some further tweaking it can even offers functionality that is beyond what legacy Mathcad X-Y Trace toolbox could offer.
Why plot tracing?
Having access to a plot tracing functionality, i.e. data tracking functionality, can be handy for those situations where you would like to study your plot trace in more detail and at the same time obtain a direct call out of the exact data point values at hand.
There are sometimes situations where you would like to highlight certain points in a plot and sometimes you might not know exactly where those points occurs until you are visualizing the results.
Below is one examples where we for some reason would like to highlight the second and third intersections of the two plot traces. In this case, we do not need the exact values where the intersections take place.

How can this be achieved?
Well, one way of doing it is to use advanced slider controls where you can “walk” along the current plot trace back and forth until you reach the current intersection of the two plot traces.
The basic setup
Firstly, we include a slider control from the Input/Output tab:

We will use variables as input to drive the slider control. Then we will add some extra code using JScript to assign the various input variables within the slider control. As output there will only be one variable.

As input, we will have three different variables:
- Start = an integer which gives the lower boundary of the slider control
- Ds = a positive scalar that decides the incremental steps when moving between the lower boundary and upper boundary.
- End = an integer that gives the upper boundary of the slider control. Must be an integer that is larger than the Start variable.
These three variables will be gathered together as a vector as shown below. Please note that the vector must be one column. If these three variables were to be gathered as a row, then it is considered as a matrix. The JScript code in this example is only applicable to a vector.
Now we will do some additional coding with JScript. To edit the advanced control just right click the mouse button and choose “edit controls”.

Then add in the highlighted text accordingly to the figure below. The first part assigns the three different input variables to internal variables within the slider control by picking the first, second and third element value from the input vector (there are some guidelines and example code in the Mathcad help section).
The second part addresses the code for setting start value of the slider as well as the end value. The delta value sets the interval value of the slider when dragging the slider handle back or forth (or up and down depending on your orientation of the slider).
The third section tweaks the slider value which also serves as the variable output.
The code within the blue box are some optional settings if you want to but, in this example, it is not needed. 
We will finish the basic setup by assigning the slider control a variable name.
Based on the input above the lower boundary of the slider control will start at: -100 x 0.05 = -5 and the upper boundary will be at 100 x 0.05 = 5 and each tick of the handle will be at 0.05.
When grabbing the slider handle you can now see how the output directly changes:

The ability to change the input variables, and doing it outside the slider control itself, gives us flexibility to change the total range and the incremental steps that we want to have. In the example that we are currently looking at we can see that the second and the third intersections between the sinus wave and the straight line is in the x-range of -4 to 4. We can adjust this range easily and at the same time we can decrease the incremental steps to just 0.01:

Now we have the basic setup of the slider control that can control one, or several, data tracking points that we can smoothly move back and forth along various plot traces. But before we could do that there are a few more things we need to consider.
Worth noting though, that in this blogpost we will only focusing on creating one slider for plot tracing but of course you can create as many unique slide controls as you need. Just copy the one you have created and give each slider control a unique variable name and if needed unique input variables.
Slider for quick plots
Let us start again with plotting the original traces that we would like to perform a data tracking on:

We will choose which plot trace we would like to put our data tracking on (we can choose both at the same time if we want). In this case we choose to perform the data tracking along the sinus wave.
Then we create another trace, or two, that uses the original trace function but we will only call-out for one X-value at a time using the slider control. We will format that trace with a different color and use a symbol with a larger font to make it more visible. Once we drag the slider handle the plot will update quickly and the data point tracker will move along the plot trace line.
To make it a little bit tidier, for demo purposes, let’s reorganize and change some variable names, switch to use the Chart Component, put most of the parts in Areas that we can collapse and finally add X- and Y-values, close to the plot, that will give us an exact call-out where the data tracking point currently is:

Closing the Areas and hide their borders, the end result will be something like this:

Slider for paired X- and Y-values
The main approach is the same as for the quick plots, but we need to make some adjustments to the final trace function.
Firstly, let’s use the same sinus wave function again and create some X- and Y-values:

And then plot it again:

Since the plot trace consists of paired X- and Y-vector values we would like to have the ability to be able to move smoothly between two vector values. This can for example be accomplished by doing/assuming a linear interpolation between two values by using the built-in linterp(x,c,d,;) function. Hence, the typical setup could look something like this:

Adding zoom functionality
Here is another idea of adding even some more functionality to your data tracking: automatic zooming.
You can control the plot window by using advanced controls such as radio buttons etc.
Here is an example where we have added a radio button and another slider to control the automatic zoom around the center of the data tracking point:

The radio button controls whether the zoom functionality around the X-axis should be utilized or not i.e returns 0 for no and 1 for yes.
The extra slide controller gives an output between 1 and 20 with a tick frequency of 1 thus giving the ability to dynamically and quickly adjust the zoom level.
The zooming ability is implemented, using if- and else-statements when defining the Xmin-value and Xmax-value in the Chart Component. In this example I choose to take 0.2*X.zoom slider value to add it, and subtract it, from the current value of x.tracking.
This gives the user the ability to smoothly use the data tracking slider handle while at the same time adopting an automatic zoom focusing on the center of the data tracking point.
Wrapping it up
A somewhat lengthier blogpost has now come to an end. While this is quite straightforward to setup your own data tracking point it does however take some effort to setup it up for the first time.
If you are just sketching and trying some various calculations on the fly, then this suggestion of implementing a data tracking point might not be worth it but if you are done with your calculations/designs and want to add some extra nifty features to your plot then this might be something worth considering.
But as with everything else, this process can be streamlined and more efficient if it is developed and designed to your catering and then save it as a part of your personal Mathcad template. Then you can recycle and implement it faster and getting more things done promptly.
If you like… you can download this Mathcad worksheet/template that I have created for this blogpost. Reach out to me and I will provide you with the file – Get in Touch!
Hopefully, this was helpful and that you found some inspirations!
If you are curious to know more about Mathcad Prime 10 please check out our webinar – Mathcad Prime 10!
Thank you for reading!
Johan Wikblad, Technical MathCAD Specialist
