필터 지우기
필터 지우기

Plot a 3D matrix (1 dependent & 2 independent variables)

조회 수: 29 (최근 30일)
Em
Em 2021년 1월 4일
편집: Cris LaPierre 2021년 1월 4일
I have a matrix with 2 independent variables (X and y) which have given data. I want to plot this data with X and Y (in the X and Y dimensions) and the corresponding data point in the Z direction so that it appears like a contour map with the independent variables giving the location and the dependent giving the magnitude. Does anyone have an idea how I could do this? Cheers

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 1월 4일
You could use mesh or surf. As an example, consider X and Y verctors, with Z defined as sin(X) + cos(Y).
X = linspace(0,2*pi,20);
Y = linspace(0,pi,10);
[X,Y] = meshgrid(X,Y);
Z = sin(X) + cos(Y);
surf(X,Y,Z)
  댓글 수: 9
Cris LaPierre
Cris LaPierre 2021년 1월 4일
편집: Cris LaPierre 2021년 1월 4일
Part of the issue with your visualization is that there are so few points. It makes it hard to see. If changing alpha works for you, that's good. Another option might be to use interpolation to increase the number of points, giving more of a surface appearance to your figure. this can be done with scatteredInterpolant. Just be careful, as interpolation might not result in accurate results.
load lowresmesh.mat mlowr
% Sortrows so
mlowr = sortrows(mlowr,[1 2 3]);
F = scatteredInterpolant(mlowr(:,1),mlowr(:,2),mlowr(:,3));
[xq,yq] = meshgrid(linspace(min(mlowr(:,1)),max(mlowr(:,1)),15),linspace(min(mlowr(:,2)),max(mlowr(:,2)),9));
zq = F(xq,yq);
surf(xq,yq,zq,'FaceColor','interp')
Em
Em 2021년 1월 4일
Thank you!! This looks exactly as I hoped.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by