MATLAB Answers

## 3D Z number as the same as input value?

Asked by Debbie

### Debbie (view profile)

on 11 Jan 2013
Accepted Answer by Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

```>>X= [1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5] <-enter
>>Y=[1     1     1     1     1
2     2     2     2     2
3     3     3     3     3
4     4     4     4     4
5     5     5     5     5] <-enter
>>z =[152    89   100   100   100
103     0   100   100   100
89    13   100   100   100
115   100   187   200   111
100    85   111    97    48] <-enter
```
```>> [x,y]=meshgrid(1:.5:5,1:.5:5);
>> z=peaks(x,y);
>> surf(x,y,z)
```

Is there any other way to represent z number exactly whatever I input? because i just want to show 3d graph from non-continues points.

#### 0 Comments

Log in to comment.

## 2 Answers

### Azzi Abdelmalek (view profile)

Answer by Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 11 Jan 2013
Accepted Answer

```x= [1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5]
y=[1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5]
z =[152 89 100 100 100 103 0 100 100 100 89 13 100 100 100 115 100 187 200 111 100 85 111 97 48]
X=reshape(x,[],5);
Y=reshape(y,[],5);
Z=reshape(z,[],5);
surf(X,Y,Z)
```

#### 4 Comments

Show 1 older comment
Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 11 Jan 2013

Try

```stem3(X,Y,z)
```

%or

```plot3(X,Y,z,'or')
```
Debbie

### Debbie (view profile)

on 12 Jan 2013

Thanks you. one more thing to do,, Do you know how to interplorate between points? so look like in graph.. surf(x,y,z) --but I don't need to use surf..though. your plot3 method is find just want to show interpolating stacks.

Walter Roberson

### Walter Roberson (view profile)

on 12 Jan 2013

Interpolating would not make sense for non-continuous points.

Log in to comment.

### Walter Roberson (view profile)

Answer by Walter Roberson

### Walter Roberson (view profile)

on 11 Jan 2013

```scatter3(X(:), Y(:), z(:))
```

Walter Roberson

### Walter Roberson (view profile)

on 12 Jan 2013

MATLAB is case sensitive. Watch out for x compared to X .

Debbie

### Debbie (view profile)

on 12 Jan 2013

Oh ! I see :) thanks

Randy Souza

### Randy Souza (view profile)

on 14 Jan 2013

For reference, this answer was previously listed as accepted due to a bug in MATLAB Answers. Debbie accepted Azzi's answer first, so I left it as the accepted answer. However, Walter does keep the reputation points earned for an accepted answer.

Log in to comment.

### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Play today