-1

I have an array of size 300x3. Three columns having data of say A,B and C variables such that range of A and B is between 0 and 1 and C's range vary i.e. my array looks like following:

A=====B=====C

0.1===0.1====x

0.1===0.2====x

0.1===0.3====x

.

.

.

0.1====1====x

0.2===0.1===x

0.2===0.2===x

and so on... I want to plot 3d plot with A,B and C on x,y and z axis respectively. Please help.

Luqman Saleem
  • 191
  • 10

1 Answers1

1

However, I don't know why there are 300 data, so I create random 100 data in [0:0.1:1] X [0:0.1:1], and there are only 100 of them.

As far as I know, are two ways to plot 3-D figures with these data. Just like Cris Luengo says, if you need a scatter/plot, use scatter3 or plot3, they are similar to ordinary plot. But if you need a surface, you have to change the struct of the data and use mesh or surf.

%%Init
clc; clear;

%%Random Data
y=0.1:0.1:1;
C=[0 0];
for i=1:10
  X=[ones(1,10)*i*0.1; y]';
  C=[C;X];
end;
C=[C(2:101,:) rand(100,1)];

%%plot scatter/lines
figure()
plot3(C(:,1),C(:,2),C(:,3),'r-')
hold on
plot3(C(:,1),C(:,2),C(:,3),'b.')

%%plot a Surface
figure()
[X,Y] = meshgrid(0.1:0.1:1,0.1:0.1:1);
nC=C(1:10,3)
for i=2:10
  nC=[nC C((i-1)*10+1:i*10,3)];
end;
mesh(X,Y,nC)

Hope this code helps.

Hunter Jiang
  • 1,300
  • 3
  • 14
  • 23