Create a surface from several 1D plots

8 views (last 30 days)
I have fitted several groups of scattered points (x,z) into 1D plots which vary on a third variable y. I now want to connect these discrete points in a 3D plot with the third axis being y. How would I go about doing this? I tried using the surf function but I need my y variable to be a matrix so I'm confused because for each entry in y (vector) a fitted (x,z) plot is created, so how could y be a matrix?
Apologies if I posed the question poorly and thank you.

Accepted Answer

DGM on 8 Sep 2021
Edited: DGM on 8 Sep 2021
Something like this:
% so you have a vector for x
x = linspace(0,1,10);
% and a bunch of vectors for z
z1 = x.^1;
z2 = x.^2;
z3 = x.^3;
z4 = x.^4;
z5 = x.^5;
% concatenate them into a matrix
z = [z1; z2; z3; z4; z5];
% define an appropriately-sized vector representing y
y = linspace(0,1,5);
% plot things
If you want more points along y than you have z-vectors, you'll need to interpolate
If there are different x-vectors, I don't really see why this won't work:
% so you have a bunch of vectors for x
nx = 10;
v = 0.05;
x0 = linspace(0,1,nx);
x1 = x0 + v*rand(1,nx);
x2 = x0 + v*rand(1,nx);
x3 = x0 + v*rand(1,nx);
x4 = x0 + v*rand(1,nx);
x5 = x0 + v*rand(1,nx);
% and a bunch of vectors for z
z1 = x1.^1;
z2 = x2.^2;
z3 = x3.^3;
z4 = x4.^4;
z5 = x5.^5;
% concatenate them into a matrix
x = [x1; x2; x3; x4; x5];
z = [z1; z2; z3; z4; z5];
% define an appropriately-sized matrix representing y
y = repmat(linspace(0,1,5).',[1 nx]);
% plot things

More Answers (1)

KSSV on 8 Sep 2021
  1. See to it that all the curves have same dimensions. If not use interp1 and get them into same size.
  2. Initliaze matrices X, Y, Z with rows as number of curves and columns as number of points in each curve.
  3. Use surf on X, Y, Z.




Community Treasure Hunt

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

Start Hunting!