Plot 4D....different contours

1 view (last 30 days)
mortain Antonio
mortain Antonio on 7 Nov 2011
Hello,
I have a set of data with 3 variables and the values of the signal.
All the three variables change in [-2,2] and the output values Y go from 800 to 1400. The values of (x1,x2,x3) are here below written:
0 -1,73205161513813 -1,73210161662818
0 -1,73205161513813 0
0 -1,73205161513813 1,73210161662818
0 0 -1,73210161662818
0 0 0
0 0 1,73210161662818
0 1,73205161513813 -1,73210161662818
0 1,73205161513813 0
0 1,73205161513813 1,73210161662818
1,73210161662818 -1,73205161513813 -1,73210161662818
1,73210161662818 -1,73205161513813 0
1,73210161662818 -1,73205161513813 1,73210161662818
1,73210161662818 0 -1,73210161662818
1,73210161662818 0 0
1,73210161662818 0 1,73210161662818
1,73210161662818 1,73205161513813 -1,73210161662818
1,73210161662818 1,73205161513813 0
1,73210161662818 1,73205161513813 1,73210161662818
-1,73210161662818 -1,73205161513813 -1,73210161662818
-1,73210161662818 -1,73205161513813 0
-1,73210161662818 -1,73205161513813 1,73210161662818
-1,73210161662818 0 -1,73210161662818
-1,73210161662818 0 0
-1,73210161662818 0 1,73210161662818
-1,73210161662818 1,73205161513813 -1,73210161662818
-1,73210161662818 1,73205161513813 0
-1,73210161662818 1,73205161513813 1,73210161662818
%Discretisation
x1fit = min(x1):.1:max(x1);
x2fit = min(x2):.1:max(x2);
x3fit = min(x3):.1:max(x3);
%Create the mesh
[X1FIT,X2FIT,X3FIT] = meshgrid(x1fit,x2fit,x3fit);
%Evaluate the Y at the different locations
b=[898.619500324491 -49.6569643950741 0.957244154182521 -0.474633267533362 0.109261217410249 0.128653191020651
0.109267525885722 0.0654684323159314 0.155519747861591 -0.265812849175710]
YFIT = b(1)+b(2)*X1FIT+b(3)*X2FIT+b(4)*X3FIT+b(5)*(X1FIT.^2-1)+b(6)*X1FIT.*X2FIT+b(7)*(X2FIT.^2-1)+b(8)*X2FIT.*X3FIT+b(9)*(X3FIT.^2-1)+b(10)*X3FIT.*X1FIT;
mesh(X1FIT,X2FIT,X3FIT,YFIT)
% I run the following program, but it gives this problem:
??? CData must be an M-by-N matrix or M-by-N-by-3 array
Error in ==> graph3d.surfaceplot.surfaceplot>localConstructor at 136
h = graph3d.surfaceplot(argin{:});
Error in ==> graph3d.surfaceplot.surfaceplot at 7
h = localConstructor(varargin{:});
Error in ==> mesh at 172
hh = graph3d.surfaceplot(x,y,z,c,'FaceColor',fc,'EdgeColor','flat', ...
Error in ==> RegressioneLineare at 42 mesh(X1FIT,X2FIT,X3FIT,YFIT)
I would like to see the surface (x1,x2,x3) coloured with the Y or contours of Y .... I guess that both tasks should be straightforward, but I am not succeding, please suggest me how to solve this issue.
Thanks a lot Antonio

Accepted Answer

LY Cao
LY Cao on 7 Nov 2011
do you mean this:
close all
clear,clc
x=[0 -1.73205161513813 -1.73210161662818
0 -1.73205161513813 0
0 -1.73205161513813 1.73210161662818
0 0 -1.73210161662818
0 0 0
0 0 1.73210161662818
0 1.73205161513813 -1.73210161662818
0 1.73205161513813 0
0 1.73205161513813 1.73210161662818
1.73210161662818 -1.73205161513813 -1.73210161662818
1.73210161662818 -1.73205161513813 0
1.73210161662818 -1.73205161513813 1.73210161662818
1.73210161662818 0 -1.73210161662818
1.73210161662818 0 0
1.73210161662818 0 1.73210161662818
1.73210161662818 1.73205161513813 -1.73210161662818
1.73210161662818 1.73205161513813 0
1.73210161662818 1.73205161513813 1.73210161662818
-1.73210161662818 -1.73205161513813 -1.73210161662818
-1.73210161662818 -1.73205161513813 0
-1.73210161662818 -1.73205161513813 1.73210161662818
-1.73210161662818 0 -1.73210161662818
-1.73210161662818 0 0
-1.73210161662818 0 1.73210161662818
-1.73210161662818 1.73205161513813 -1.73210161662818
-1.73210161662818 1.73205161513813 0
-1.73210161662818 1.73205161513813 1.73210161662818];
%Discretisation
[x1,x2,x3]=deal(x(:,1),x(:,2),x(:,3));
x1fit = min(x1):.1:max(x1);
x2fit = min(x2):.1:max(x2);
x3fit = min(x3):.1:max(x3);
%Create the mesh
[X1FIT,X2FIT] = meshgrid(x1fit,x2fit);
X3FIT=griddata(x1fit,x2fit,x3fit,X1FIT,X2FIT,'v4');
%Evaluate the Y at the different locations
b=[898.619500324491 -49.6569643950741 0.957244154182521 -0.474633267533362 0.109261217410249 0.128653191020651 0.109267525885722 0.0654684323159314 0.155519747861591 -0.265812849175710];
YFIT = b(1)+b(2)*X1FIT+b(3)*X2FIT+b(4)*X3FIT+b(5)*(X1FIT.^2-1)+b(6)*X1FIT.*X2FIT+b(7)*(X2FIT.^2-1)+b(8)*X2FIT.*X3FIT+b(9)*(X3FIT.^2-1)+b(10)*X3FIT.*X1FIT;
surf(X1FIT,X2FIT,X3FIT,YFIT)
  1 Comment
mortain Antonio
mortain Antonio on 7 Nov 2011
So I had the use the command surf! Thanks a lot!
If I have more than one value of b (hence different YFIT) is it possible to create something like a movie which show how the YFIT change?
Thanks a lot again
Anonio

Sign in to comment.

More Answers (0)

Categories

Find more on Contour Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!