How to convert the data from three array: x,y,z into mesh format
Show older comments
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,
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
Stephen23
on 17 Sep 2018
>> 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
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!