2

I am struggling with something that should not be too hard; I have three variables (x,y,z) and an outcome (e), and I know the relationship between them. Let's for the sake of it assume that the relationship is as follows:

e = x + y.^2 + (4/z)    

Now, what I want to do is create a plot in MATLAB that shows me this function, with the three variables on the respective axes, and the color reflecting the outcome (e). I know it probably has something to do with meshgrid and surf, but from the way I see it, those can only plot three variables total, and not four, as in my case.

Thanks in advance for your help,

  • 2
    Get thee to any book by Ed. Tufte. Make sure you know what story you want to tell the observer before designing your graph. – Carl Witthoft Feb 18 '16 at 16:45
  • 1
    Nice advice by @Carl. Martijn, think: how should the plot look: do you want a surface, lines, single points? Are you sure that the observer really understands such a plot and can interpret it? Or might a simpler plot be more appropriate? You could create such a plot by creating `x,y,z` values with `meshgrid`. The `surf` function (and many others) have a fourth parameter `C`, which is the color of each data point. I.e. you can simply call `surf(x,y,z,e)`. – hbaderts Feb 18 '16 at 16:51
  • Thanks for the answers! I think a way that the plot can be simplified is by creating a plane of the variables (x,y,z) that result in zero error (e). Ultimately, the goal is to have this plane (the criteria that satisfy the task) and then overlay this with the actual observed variables (x,y,z) and calculate an error score as the orthogonal distance from the function. I hope this simplifies my problem. – Martijn Verhoeven Feb 18 '16 at 17:07
  • 1
    Have a look here: https://stackoverflow.com/questions/27659632/reconstructing-three-dimensions-image-matlab/27660039#27660039 – Ander Biguri Feb 18 '16 at 17:11

1 Answers1

0

I tried out using isonormals() and it gave a useful plot:

isonormals plot

The red surface corresponds to e = 0, whereas blue and green surfaces show e = 5 and e = -5 respectively.

Here is the code:

clear;

[x, y, z] = meshgrid(-30:0.5:30, -10:0.5:10, -1:0.01:1);

e = x + y.^2 + 4./z;

e1 = 0; e2 = 5; e3 = -5;
e_val = [0, 5, -5];
c_val = ['r', 'b', 'g'];

for i=1:length(e_val)
    p = patch(isosurface(x,y,z,e,e_val(i)),'FaceColor',c_val(i),'EdgeColor','none');
    isonormals(x,y,z,e,p); 

    hold on;
end
hold off;

xlabel('X');ylabel('Y');zlabel('Z');

view(3); axis tight;
camlight;
lighting gouraud;
Anton
  • 4,544
  • 2
  • 25
  • 31