Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
3d representation of 3 variables

Subject: 3d representation of 3 variables

From: MOOON MOOON

Date: 20 Aug, 2011 16:37:08

Message: 1 of 4



Hello,

 I have a problem relating to 3d representation using mesh commands

I have 3 matrices X, Y and Z

All matrices have the same number of entries and they are row vectors, i.e. 1 by m

All the data are real values measured experimentally.

I want to plot these matrices in three dimension plot as a plane or surface to

see the impact of X and Y on Z using mesh commands.

I wrote the following code:

% every matrix contains, for example, 10 elements

X=rand(1,10);
Y=rand(1,10);
Z=rand(1,10);

[XX,YY]=meshgrid(X,Y);


I know that ZZ must be m by m matrix, so in this example ZZ must be

10 by 10 matrix but how can we enforce it to be 10 by 10 matrix ?

In all the examples I have seen, ZZ is a function of XX and YY and is directly

found from a formula. But in my case, Z is a matrix containing elements and its size

is the same as X and Y which are 1 by 10. Also, in my case Z is a function of X and Y

but this function is not known. I think one solution is to find a formula Z = f ( X , Y )

and then proceed as this example:

X=rand(1,10);
Y=rand(1,10);
Z=rand(1,10);
[XX,YY]=meshgrid(X,Y);
ZZ = X .* exp(-XX.^2 - YY.^2);
mesh(XX,YY,ZZ)
 

but it is difficult to find Z = f ( X , Y ) since I have huge data and it is difficult

to make curve fit or least square method to find such formula.

Could you please help me in this problem.

Regards

Subject: 3d representation of 3 variables

From: Bruno Luong

Date: 20 Aug, 2011 16:52:07

Message: 2 of 4

Please try

> trisurf(delaunay(X,Y),X,Y,Z)

and see how it goes.

Bruno

Subject: 3d representation of 3 variables

From: MOOON MOOON

Date: 21 Aug, 2011 01:21:08

Message: 3 of 4

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <j2oonn$rae$1@newscl01ah.mathworks.com>...
> Please try
>
> > trisurf(delaunay(X,Y),X,Y,Z)
>
> and see how it goes.
>
> Bruno

thanks for this help..

Great..

So, this figure is shown using triangular shape.

What should we use if we want to plot the data using mesh and meshgrid commands shapes?

 thanks

Subject: 3d representation of 3 variables

From: Bruno Luong

Date: 21 Aug, 2011 07:55:11

Message: 4 of 4

"MOOON MOOON" wrote in message <j2pmi4$ke5$1@newscl01ah.mathworks.com>...
>
>
> What should we use if we want to plot the data using mesh and meshgrid commands shapes?

Your original data is NOT on a grid, thus you can't directly use these commands.

Unless if you interpolate it in a regular grid using command such as GRIDDATA.

X=rand(1,30);
Y=rand(1,30);
Z=rand(1,30);

[XI YI ZI] = griddata(X,Y,Z,linspace(0,1),linspace(0,1)');

figure
subplot(1,2,1)
trisurf(delaunay(X,Y),X,Y,Z)
subplot(1,2,2);
surf(XI,YI,ZI)

% Bruno

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us