How do I create surface between curves of differing amounts of data points
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to plot curves in seperate planes and draw surfaces connecting them. so far i have managed this with;
x1=linspace(0, pi, 100)
x2=linspace(0, pi, 100)
z1=sin(x1)
z2=sin(x2)
k1=ones(1, length(x1))
k2=2*ones(1, length(x2))
plot3(k1, x1, z1); hold on; plot3(k2, x2, k2)
surf([k1;k2], [x1;x2], [z1;z2], 'meshstyle', 'row')
However, the surf function isnt working when I create x2 and x1 with differing numbers of data points such as;
x1=linspace(0, pi, 50)
x2=linspace(0, pi, 25)
Thurthermore any way to smooth the boundaries of the curves would be greatly appreciated as im am very new to this. Thanks in advance.
댓글 수: 0
답변 (1개)
Tony
2024년 7월 2일
편집: Tony
2024년 7월 2일
One method is to expand to use the union of reference data points, and then apply the two functions to the union reference
x1=linspace(0, pi, 50);
x2=linspace(0, pi, 25);
x12 = unique([x1 x2]);
z1=sin(x12);
z2=sin(x12);
k1=ones(1, length(x12));
k2=2*ones(1, length(x12));
figure(1); tiledlayout(1, 2);
nexttile; plot3(k1, x12, z1); hold on; plot3(k2, x12, z2);
nexttile; surf([k1;k2], [x12;x12], [z1;z2], 'meshstyle', 'row');
But if you don't have the original function, you can interpolate the data
x1=linspace(0, pi, 50);
x2=linspace(0, pi, 25);
z1=sin(x1);
z2=sin(x2);
x12 = unique([x1 x2]);
z1_12 = interp1(x1, z1, x12);
z2_12 = interp1(x2, z2, x12);
k1=ones(1, length(x12));
k2=2*ones(1, length(x12));
figure(2); tiledlayout(1, 2);
nexttile; plot3(k1, x12, z1_12); hold on; plot3(k2, x12, z2_12);
nexttile; surf([k1;k2], [x12;x12], [z1_12;z2_12], 'meshstyle', 'row');
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!