現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Extend line plot to a Surface
15 ビュー (過去 30 日間)
古いコメントを表示
Mazhar
2013 年 7 月 23 日
Hey, I am trying to plot a surface but am struggling to find the right commands. I have a 2D plot of a line going diagonally down. I want to extend this line to the 3rd dimension, so that it creates a surface. Is it possible to do this in MatLab? What commands can I use. Thanks
採用された回答
kjetil87
2013 年 7 月 23 日
編集済み: kjetil87
2013 年 7 月 23 日
x=10:-1:1; % your 2d_line
x3d=repmat(x,[numel(x),1]);
surf(x3d);
22 件のコメント
Mazhar
2013 年 7 月 23 日
Looks like this does the job :) Thanks. Could you please quickly explain how the 'repmat' and 'numel' commands work?
kjetil87
2013 年 7 月 23 日
編集済み: kjetil87
2013 年 7 月 23 日
repmat basicly repeats your vector x times. i.e
x=[1,2];
repmat(x,[2,1])
ans =
1 2
1 2
repmat(x,[1,2])
ans =
1 2 1 2
The numel command just counts the number of elements in x. you dont really have to use the umel command you can specify a different numer if you want like i did above.
kjetil87
2013 年 7 月 23 日
also im not sure if i did the dimensions correcly to make it comply with what you needed, try
hold on;
xlabel('x')
ylabel('y')
zlabel('z')
To make sure it ended up as inteted. Otherwise try to
transpose
the matrix
Mazhar
2013 年 7 月 23 日
Sorry stuck again! I've just tried to make this work for my data and could not work it.
My data for plotting the line is; x=[0 1 2 3 4 5]; y=[5 3 2.5 2 1.5 0];if true
How would you do it for this set of data?
Mazhar
2013 年 7 月 24 日
This problem is killing my brain!
So I am trying to achieve this: I have 2 line graphs;
in (x,z) plane: x=[0 1 2 3 4 5]; z=[5 3 2.5 2 1.5 0];
in (x,y) plane: x=[0 2 3 4 4.5 5]; y=[5 3 2.5 2 1.5 0];
I want to extend both these line graphs in the third dimension and plot a line where they intersect.
For plotting the line of intersection I would need to use something like this:
% Take the difference between the two surface heights and find the contour
% where that surface is zero.
zdiff = z1 - z2;
C = contours(x, y, zdiff, [0 0]);
% Extract the x- and y-locations from the contour matrix C.
xL = C(1, 2:end);
yL = C(2, 2:end);
% Interpolate on the first surface to find z-locations for the intersection
% line.
zL = interp2(x, y, z1, xL, yL);
% Visualize the line.
line(xL, yL, zL, 'Color', 'k', 'LineWidth', 3);
But I am struggling with the first part.
Thanks again for all your help.
Mazhar
2013 年 7 月 24 日
Yeah!
But thinking about it now I will probably also struggle to do the second part as my surfaces aren't defined by equations so can't really solve for zdiff :(
Mazhar
2013 年 7 月 24 日
Also, I posted the question again with a bit more detail and an image to explain the problem.
Please have a look at it and see what you would suggest.
kjetil87
2013 年 7 月 24 日
編集済み: kjetil87
2013 年 7 月 24 日
hm.. well, the plot i gave you earlier were`nt entirely correct.
x=[0 2 3 4 4.5 5];
y=[5 3 2.5 2 1.5 0];
z=0:5;
x3d=repmat(x,6,1);
y3d=repmat(y,6,1);
z3d=repmat(z,6,1).';
figure;surf(x3d,y3d,z3d); % now it is the correct plane.
%then the x-z line:
x=[0 1 2 3 4 5];
z=[5 3 2.5 2 1.5 0];
y=0:5;
x3d2=repmat(x,6,1);
y3d2=repmat(y,6,1).';
z3d2=repmat(z,6,1);
hold on;
surf(x3d2,y3d2,z3d2);
xlabel('x');ylabel('y');zlabel('z');
Atleast now you can visualize the surfaces. As for the interpolation and intersection i think maybe it should be possible if you interpolate each vector before using repmat (you will probably need to change the "6" in repmat also then). the intersection should then be where the values in all 3 matricies (x3d==x3d2 etc) are the same (within some limit )
Mazhar
2013 年 7 月 24 日
Thank you so much, you really came through kjetil87.
I see what you mean about the interpolation part. I'll have a go at that now. Please don't mind if I get stuck at that too and come crawling back to you :P
Thanks again.
Mazhar
2013 年 7 月 25 日
The code is working perfectly. I tried it for my larger set of data and it works there too.
Only one more thing! The length of z has to be the same as the length of the other two variables, in order for the dimensions to match for the surf command. Is there a way to not be limited in how far I can extend the plot? i.e. z=0:100;!
kjetil87
2013 年 7 月 25 日
編集済み: kjetil87
2013 年 7 月 25 日
Cool , nice to hear it works!
Yes,in
surf(x,y,z)
the lengths must be equal to length(x)=n and length(y)=m , where [m,n]=size(z). Or atleast thats what the instruction says (help surf). But according to "surfchk" in "surf", size(x) must be equal to size(z) , and size(y) must be equal to size(z) .
so :
x=[0 2 3 4 4.5 5];
y=[5 3 2.5 2 1.5 0];
z=0:99;
zn=length(z);
x3d=repmat(x,zn,1);
y3d=repmat(y,zn,1);
z3d=repmat(z,6,1).';
figure;surf(x3d,y3d,z3d);
xlabel('x');ylabel('y');zlabel('z');
kjetil87
2013 年 7 月 25 日
also i think you can leave either y3d or x3d in 2d, but it really doesnt matter.
Mazhar
2013 年 7 月 25 日
Great! Now I can always have my surfaces cutting through!
Now to move forward to line of intersection.
Thanks again :D
Mazhar
2013 年 7 月 26 日
Hey, me again!
Having trouble trying to get the intersection line! I have been looking at interpolations I can't find anything good for 3D that I could use for my problem!
One thing I am thing might work, is if I check the x3d, y3d, z3d matrices for the two plots for equal values! but not sure if that would give me what I'm looking for!
You have any suggestions?
kjetil87
2013 年 7 月 26 日
編集済み: kjetil87
2013 年 7 月 26 日
Im not a 100% sure if it will work, but e.g as of now there is two common points that are given in the vectors namely ,
(x3d==x3d2 & y3d==y3d2 & z3d==z3d2 )
what you need to do is to interpolate x, y and z before using repmat so your resolution is increased , then instead of x3d==x3d2 you can use
abs(x3d-x3d2)< tol
where tol is a very small number.
(so then you can use interp1 since you are not interpolating in 3d)
Mazhar
2013 年 7 月 26 日
Ok, I see what you mean! Trying it out just now and it seems to be working so far!
Hopefully can get this section done and over with now!
Mazhar
2013 年 8 月 2 日
kjetil87, Thank you very much for all your help!
that's all of my problem sorted now. I have a nice plot of the line intersecting the the two surfaces :D
その他の回答 (0 件)
参考
カテゴリ
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)