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 Plot

Subject: 3D Plot

From: Max

Date: 23 Jun, 2006 06:47:27

Message: 1 of 10

As an early EE major, I'm very new to Matlab so go easy on me. I have
a data set in the form of an excel document. The first column is the X
values, 2nd-13th colum are each Y 'points' and under those columns are
the Z values. How should I go about plotting a 3D mesh with these
data? Thanks.

Subject: 3D Plot

From: spok

Date: 23 Jun, 2006 07:18:37

Message: 2 of 10

Hi,

try this : (consider A your matrix from excel)

[X,Y] = meshgrid(A(:,1),A(1,2:13))
Z = A(2:end,2:13);
mesh(X,Y,Z)

or surf(X,Y,Z) ...

or help mesh ! :-)

S.

Subject: 3D Plot

From: Max

Date: 23 Jun, 2006 08:13:10

Message: 3 of 10


spok wrote:
> Hi,
>
> try this : (consider A your matrix from excel)
>
> [X,Y] = meshgrid(A(:,1),A(1,2:13))
> Z = A(2:end,2:13);
> mesh(X,Y,Z)
>
> or surf(X,Y,Z) ...
>
> or help mesh ! :-)
>
> S.

Thanks for the speedy reply!
Well, lets call my A data, I ran

[X,Y] = meshgrid(data(:,1),data(1,2:14))
Z = data(2:end,2:14);
mesh(X,Y,Z)

It gave me:

??? mesh(X,Y,Z) [X,Y] = meshgrid(data(:,1),data(1,2:14))
                |
Error: Unbalanced or misused parentheses or brackets.

PS. It's no longer 13 columns, it's 14, and I've changed it in the code.

Subject: 3D Plot

From: Max

Date: 23 Jun, 2006 08:20:37

Message: 4 of 10

I've fiddled around with it some more, now the errors are just:

Warning: Matrix dimensions must agree, not rendering mesh.

Subject: 3D Plot

From: Jerome

Date: 23 Jun, 2006 11:27:21

Message: 5 of 10

Hi,

here is a small example :

M=[0:5; (1:5)' rand(5)]

[X,Y]=meshgrid(M(2:end,1),M(1,2:end));

surf(X,Y,M(2:end,2:end))

Jérôme

Subject: 3D Plot

From: Max

Date: 23 Jun, 2006 09:03:03

Message: 6 of 10


J=E9r=F4me wrote:
> Hi,
>
> here is a small example :
>
> M=3D[0:5; (1:5)' rand(5)]
>
> [X,Y]=3Dmeshgrid(M(2:end,1),M(1,2:end));
>
> surf(X,Y,M(2:end,2:end))
>
> J=E9r=F4me

Thanks, I understand it a little better now. However, I'm running into
errors such as:

Mismatch between file and format string.

I've had education in C++, and by looking at a code I was given, it's
hard to say why.

Here's the code given to me:

clear all;close all;home; %Initialize workspace
cd('c:\matlab\');

data =3D dlmread('FBG1-13A.dat',',');
[i q] =3D size(data); %get the size of data
n=3D1;
while n <=3D 14
    data( (n*i)+1:1:(n*i)+i,1) =3D 0; %Build zero matrix
    data( (n*i)+1:1:(n*i)+i,1) =3D data(1:1:i,1); %copy time axis
column1
    data( (n*i)+1:1:(n*i)+i,2) =3D data(1:1:i,(2*n)); %copy pos axis
column 2n
    data( (n*i)+1:1:(n*i)+i,3) =3D data(1:1:i,(2*n)+1);%copy temp
    n=3Dn+1;
end

pi =3D linspace(34,98,100); %Region of support for positioning
ti =3D linspace(0,14.5,100); %Region of support for time

[XI,YI] =3D meshgrid(ti,pi); %Two dimensional mesh, rectangular
ZI =3D griddata(data(:,1),data(:,2),data(:,3),XI,YI); %Fit into
topological surface
surf(XI,YI,ZI) %Graph surface
axis tight
xlabel('Time (hr)');
ylabel('Position (ft)');
zlabel('Temperature (F)');

Subject: 3D Plot

From: Jerome

Date: 23 Jun, 2006 12:10:36

Message: 7 of 10

Could you post a small example for the ascii file ?

Jérôme

Subject: 3D Plot

From: Max

Date: 23 Jun, 2006 10:32:09

Message: 8 of 10


J=E9r=F4me wrote:
> Could you post a small example for the ascii file ?
>
> J=E9r=F4me
Sure thing.

0 97.03478 98.52174
2=2E343608 97.03478 98.52174
2=2E343886 96.98782 98.70956
2=2E344163 96.98782 98.6313
2=2E344441 96.94087 98.85043
2=2E344719 97.05044 98.6

The first column is the time in seconds.
Second-third (14 total) column is 13 data sets with hundreds of rows of
data.

Subject: 3D Plot

From: spok

Date: 26 Jun, 2006 07:46:34

Message: 9 of 10

oups, sorry, I left a little bit early last friday ! ;o)
and I think I wrote that quick and I made a little mistake.. :o)

from your ex., that we'd called it data ;o) and let say that the first
column is your x, and the first row your y (stop me if it is not)

type:

[x y] = meshgrid(data(1,2:end),data(2:end,1));
z = data(2:end,2:end);
surf(x,y,z)

should do the work properly.

Subject: 3D Plot

From: Christopher Rouxel

Date: 15 Jul, 2010 20:22:22

Message: 10 of 10

Howdy,
 check out my file:
http://www.mathworks.com/matlabcentral/fileexchange/28177-3d-performance-map-gui
Cheers,
Chris

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