Create a surface from several 1D plots

조회 수: 8 (최근 30일)
Diogo Carvalho
Diogo Carvalho 2021년 9월 8일
편집: DGM 2021년 9월 8일
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.

채택된 답변

DGM
DGM 2021년 9월 8일
편집: DGM 2021년 9월 8일
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
surf(x,y,z)
If you want more points along y than you have z-vectors, you'll need to interpolate
EDIT:
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
surf(x,y,z)

추가 답변 (1개)

KSSV
KSSV 2021년 9월 8일
  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.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by