Plotting two dependent function with respect to each other

I am writing a small code in Matlab to achieve following:

X, Y, and Z are all vectors and correspond to different physical quantities.

x1 and x2 are two different vectors made from allowed values which X can have.

Now I have Y as function of x1


and Z as function of x2


I do not know the functions 'f' and 'g' explicitly but I have a table which gives me Y and Z corresponding to x1 and x2 respectively.

So I can plot Y=f(x1) and Z = g(x2) in MATLAB using plotyy function using a common x-scale but 2 different y axis.

I want to plot Y as function of Z. What will be the most efficient way to do this? I guess I might need to use interpolation somewhere in this.

Thanks in advance !


As mentioned by @mikkola, interpolation would be the way to go. You could interpolate Y onto the domain of Z, Z onto the domain of Y, or Y and Z onto a completely different domain. Do be careful though, as you want to make sure you interpolate, not extrapolate. The default for interp1 is linear interpolation, but you can get it to implement other types of interpolation by passing in an optional parameter.

The following is an example with two different domains x1 and x2, corresponding to functions Y=sin(x) and Z=cos(x). These are interpolated onto a different domain x3 so that Y and Z can be plotted against each other, yielding a circle as we would expect.

% Two different domains
x1 = 0:0.02:2*pi;
x2 = 0:0.03:2*pi;

% Yielding two different functions
Y = sin(x1);
Z = cos(x2);

% Interpolate them both onto a common domain (x3)
x3 = 0:0.01:2*pi;
Yi = interp1(x1,Y,x3);
Zi = interp1(x2,Z,x3);

% Plot - circle, as expected

Need Your Help

Choosing to not use delegates in a C# program

c# linq events methods delegates

I am trying to understand delegates in C#. I know they are a must in many scenarios like linq etc., but in simple console application, would my life be so miseable if i choose to not use it? I am not

GPUImage Filter Returning nil

ios swift image-processing gpuimage

I've been trying to apply the GPUImageHoughTransformLineDetector to a UIImage in Swift but it's giving me nothing and for a couple of hours now i can't figure what i'm doing wrong.