필터 지우기
필터 지우기

How do I create surface between curves of differing amounts of data points

조회 수: 2 (최근 30일)
Rowan
Rowan 2024년 7월 2일
댓글: Rowan 2024년 7월 2일
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.

답변 (1개)

Tony
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');
  댓글 수: 1
Rowan
Rowan 2024년 7월 2일
thank you, this is extremely helpful. i have used the second method as i intend to use this on real data and this is practice/testing what is possible and have had success with creating a surface like above.
However, i have ran into an issue and found that i need the domain, x1 and x2, to start and end at the same point regardless of if they have the same number of points or not. For example, say you have two functions z1 and z2 where z1 has 100 data entries and z2 has 50. i have sets x1 and x2 which are just a series of integers created by;
x1=reshape(1:100, 1, 100)
x2=reshape(1:50, 1, 50)
I belive this creates a problem when using
z2_12 = interp1(x2, z2, x12)
as x12 now has entreis greater than the greatest in x2. x12 is just x1 as it x2 is a subset of points of x1 and therefore the 51st entry and any subsequent one is just "NaN". I'd assume this is because x2 is 1 through 50 but x12 is 1 thorugh 100. I have circumvented this by creating x2 by
x2=2*reshape(1:50, 1, 50)
so that x2 is 2, 4, 6, ..., 100. However this isnt wouldnt be suitlible for real data. If you have any fix to this that would be amazing i clearly have no clue what im doing. Thanks again.

댓글을 달려면 로그인하십시오.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by