フィルターのクリア

How can I plot various vectors together with surf or mesh when they have different x, y and z values?

3 ビュー (過去 30 日間)
Hello,
assuming I have 4 times of these two vectors
G=[-1 2 5 -3 3 4] %(x)
P=[36 45 23 54 56 23] %(y)
G=[2 -3 5 -3 3 1]
P=[46 23 45 79 23 12]
G=[2 2 -3 2 3 -1]
P=[36 45 23 54 56 23]
G=[-1 -4 -4 -3 3 2]
P=[36 37 14 54 56 56]
each and every pair gives you a plot if you just do plot(G,P)
What I want to do is plot them on a mesh or surf so that X axis will have the P values Y axis will have the G values for each P and the Z axis will just be a number from 1:4 or as many the plots are.
my thoughts up to now come to interpolation in order to fix all the P values somehow , but I really do not know how to do it.
Any suggestions?
/Andreas T.

採用された回答

Sreeja Banerjee
Sreeja Banerjee 2015 年 6 月 8 日
Hi Andreas,
From your question I understand that you have two 1D vectors G and P. These vectors can have different values at different instances, for example, in the question you have mentioned 4 different pairs of G and P. You want to create a surface plot with these two vector and have the four different values shown on four different levels (z-axis).
Since G and P are only 1D vectors, we cannot create a surface plot which them. However, we can use the function MESHGRID to create a rectangular grid in 2-D. I have shown below a simple exmple on how you can do that:
G=[-1 2 5 -3 3 4];
P=[36 45 23 54 56 23];
[x,y] = meshgrid(G,P);
z = 0*x + 1;
surf(x,y,z,'Marker','*');
hold on;
G=[2 -3 5 -3 3 1];
P=[46 23 45 79 23 12];
[x,y] = meshgrid(G,P);
z = 0*x + 2;
surf(x,y,z,'Marker','*');
hold on;
G=[2 2 -3 2 3 -1];
P=[36 45 23 54 56 23];
[x,y] = meshgrid(G,P);
z = 0*x + 3;
surf(x,y,z,'Marker','*');
hold on;
G=[1 -4 -4 -3 3 2];
P=[36 37 14 54 56 56];
[x,y] = meshgrid(G,P);
z = 0*x + 4;
surf(x,y,z,'Marker','*');
hold off;
The figure obtained is as follows:
You can read more about MESHGRID at the following documentation: http://www.mathworks.com/help/matlab/ref/meshgrid.html

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by