plotting 3 independent data and 1 response (output)

59 views (last 30 days)
Hello
I have data of 3 independent variables and one output. you can think of it as 3 columns of data and one response variable. I wonder if I can plot a surface that shows the variation in the respons or output variable as the other 3 data variables change.
Thank you
Aziz

Accepted Answer

William Rose
William Rose on 1 Mar 2021
What you are requesting would require a 4 dimensional plot. Let's call the output variable P and the inputs x,y,z. Several options exist:
1. Make surface plots of P on the vertical axis versus pairs of input variables, while holding the third variable constant: P vs x,y at fixed z; P vs y,z at fixed x; P vs z,x at fixedy.
2. Calculate a surface of constant P and make a 3D plot of that surface in x,y,z space. This sounds hard but Matlab has a great funciton, isosurface(), to make this easy.
The plots below illustrate option 1 (left) and option 2 (right), for the function
p(x,y,z)=(1-abs(x))*cos(y*pi/2)*cos(z*pi*3);
Code to make the figures is attached. The same color scale is used in both sets of plots. The left hand plots have p() on the vertical axis; the right hand plots show surface of constant p, in x,y,z space. For the plots on the right, I rotated each plot by hand to a perspective that I liked more than the default perspective, before doing the screen shot. When you hover the cursor over the plot area for a few seconds, some icons appear at the top right of the plot area. One icon is a little cube with a circular arrow around it. Click it. Then you can click and driag in the plot area to rotate it in 3D.
  3 Comments
William Rose
William Rose on 22 Mar 2021
Aziz, You could do this with experimental data. To use these plotting routines, your data needs to be sampled on a regular grid that has constant spacing along each axis. The spacing can be different on different axes. If your experimental samples are not all regularly spaced, or if you have a grid with some missing data, you would need to interpolate your data to estimate the values on a regular 3D grid. For visually pleasing results in 3D, you need a reasonablty dense grid, such as a minimm of 10 points along each dimension, in my opinion. In the example I posted, there were 21 points in each dimension, i.e. points - a lot of points!
Once you figure out how to do 3D interpolation, it is easy to generate a lot of points by interpolation. You will have to use your good judgeent to decide if you believe in those estimated values. It is good to be cautious if the interpolated data set is several times larger than the experimental data set.
To do 3D interpolation, use F=scatteredInterpolant(). The Matlab Help for scatteredInterpolant() has some good examples. An important difference between the examples in the Help and your situation is that you will need to read the experimental data from a file, before you call scatteredInterpolant().
Bill

Sign in to comment.

More Answers (1)

William Rose
William Rose on 23 Mar 2021
This version of the code reads 4D experimental data (x,y,z,p) from a file and plots it in multiple ways, like script I posted previously. Experimental data may not be exactly on a grid, or may have missing data points. Therefore the experimental data is interpolated and evaluated at all points on a 3D grid before plotting.
The output from the program is two figures with three plots each. Figure 1 (left) shows interpolated p versus x,y at a fixed level of z, and p vs. y,z at fixed x, and p versus x,z at fixed y. Figure 2 shows three iso-p-surfaces in x,y,z space, i.e. three surfaces, each of which has a constant value of p. These figures use datat file 3 described beow.
Attached files: the script to read, interpolate, and plot the data; four text files of simulated data to use as inputs to the program. Each text file has four columns: x,y,z,p. Simulated data files:
1. fourDdataGridN00.txt: 11x11x11 values of p on a regular x,y,z grid, with no measurement noise.
2. fourDdataRandN00.txt: 512 values of p at randomly chosen points in the sample volume, with no measurement noise.
3. fourDdataRandN02.txt: 512 values of p at randomly chosen points in the sample volume, with measurement amplitude=0.02.
4. fourDdataRandN04.txt: 512 values of p at randomly chosen points in the sample volume, with measurement amplitude=0.04.
  2 Comments
Abdulaziz Abutunis
Abdulaziz Abutunis on 24 Mar 2021
Wow that is so kind of you William, your codes are really helpful. I appreciate your help.
Best regards
Aziz

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!