필터 지우기
필터 지우기

How to plot 4D graph ?

조회 수: 3 (최근 30일)
Neeraj Bhanot
Neeraj Bhanot 2015년 6월 21일
편집: Walter Roberson 2015년 6월 21일
I have two functions "f" and "g" and both are dependent on three variables being x,y and z. Both the functions and boundaries of x, y and z are provided as follows:
x = 150:5:250;
y = 0.2:0.05:0.3;
z = 1:0.1:2;
f = 20./(x.^0.2) .* (y.^0.3) .* (z.^0.01);
g = x .* y .* z
How can both the functions be plotted in one graph itself. Please help.

답변 (1개)

Hugo
Hugo 2015년 6월 21일
편집: Walter Roberson 2015년 6월 21일
You can use scatter3. To that end, you can create a matrix containing in each row the coordinates of each point and the value of f or g. Suppose the matrix is called M and the columns are the x, y, z values and the function. Then write:
scatter3(M(:,1),M(:,2),M(:,3),5,'o',M(:,4))
and you will get each point with a different colour representing the value of f or g. Write:
scatter3(M(:,1),M(:,2),M(:,3),M(:,4),'o')
and you will get each point with a different size representing the value of f or g. Write
scatter3(M(:,1),M(:,2),M(:,3),M(:,4),'o',M(:,5))
and you will get the points with different sizes and different colours representing both f and g.
Whether it represents f and/or g depends on what you put in the columns 4 and 5.
Just in case, check the usage of scatter3 in the Matlab help. I might have messed up the order of the last inputs.
Hope this helps.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by