How to convert the data from three array: x,y,z into mesh format

Hi, I have three 1D-arrays x,y,z. They have exactly equal length, but the data don't have any analytical expression. In order to plot them in 3D (surface or mesh plot), I need to convert them into mesh format. Typical data set looks as follows-
x y z
1 1 4
1 2 5
1 3 3
2 1 2
2 2 7
2 3 6
How can I convert the x,y and z into mesh format?

Answers (2)

Hi,
if your x-data and y-data is sorted this way you can simply do a transposed reshape :
x = [1 1 1 2 2 2];
y = [1 2 3 1 2 3];
z = [4 5 3 2 7 6];
mesh = reshape(z,3,2)'
gives:
mesh =
4 5 3
2 7 6
Best regards
Stephan
>> X = [1,1,1,2,2,2];
>> Y = [1,2,3,1,2,3];
>> Z = [4,5,3,2,7,6];
>> uX = unique(X);
>> uY = unique(Y);
>> S = [numel(uY),numel(uX)]; % or swap, depending on what order you want.
>> Xm = reshape(X,S)
Xm =
1 2
1 2
1 2
>> Ym = reshape(Y,S)
Ym =
1 1
2 2
3 3
>> Zm = reshape(Z,S)
Zm =
4 2
5 7
3 6

Categories

Tags

Asked:

on 16 Sep 2018

Answered:

on 17 Sep 2018

Community Treasure Hunt

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

Start Hunting!