2d surface or contour plot of three independent variables
조회 수: 16 (최근 30일)
이전 댓글 표시
Hello all,
i have a set of data as given above in csv format.
I want to plot column 1, 5 and 6 as given in attached plot. I want to plot as 2d surface or contour.
My code is not working.
Please help.
clear
clc
sweep=readtable('TM_sweep.csv');
x = sweep(:,1);
y = sweep(:,5);
z = sweep(:,6);
[X,Y] = meshgrid(x,y);
Z=diag(z);
surface(X,Y,Z)
댓글 수: 0
채택된 답변
Star Strider
2022년 10월 13일
편집: Star Strider
2022년 10월 13일
The data are gridded. It is simply necessary to reshape them to plot them —
sweep = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1154768/TM_sweep.csv', 'VariableNamingRule','preserve')
x = sweep{:,1};
y = sweep{:,5};
z = sweep{:,6};
VN = sweep.Properties.VariableNames;
[Ux,ix1] = unique(x); % Unique 'x' Values
dim1 = diff(ix1); % Get Row Dimension For Reshaped Matrix
Ud1 = unique(dim1); % Be Certain This Is Constant
X = reshape(x,Ud1,[]);
Y = reshape(y,Ud1,[]);
Z = reshape(z,Ud1,[]);
figure
surf(X, Y, Z)
grid on
xlabel(VN{1})
ylabel(VN{5})
zlabel(VN{6})
colormap(turbo)
colorbar
shading('interp')
figure
contourf(X, Y, Z, 50)
xlabel(VN{1})
ylabel(VN{5})
colormap(turbo)
hcb = colorbar;
hcb.Label.String = VN{6};
Make appropriate changes to get the desired result.
EDIT — (13 Oct 2022 at 12:28)
Added label to contour colorbar.
.
댓글 수: 4
Harlan Johnson
2023년 2월 23일
I am trying to plot some cruise CTD data in 3-D, and usueally
I cut-and-pasted this example and got this error message. The script loaded all the variables but could
not reshape the vectors into matrices.
Error in example3D (line 9)
X = reshape(x,Ud1,[]);
I am trying to do a 3D plot of some large CTD data from a cruise and am using your examples to learn how to do this. Any help is appriated. Thanks!
Paul Johnson paulj@uw.edu
Star Strider
2023년 2월 24일
If the ‘CTD’ data are gridded, it may be necesary to find the unique values of a different independent variable, since they may not all have the same structure as these data did. If they are not gridded, then it would be necessary to grid them first. This is relatively straightforward, however it would then require the scatteredInterpolant function for the best result with respect to interpolating them to create the required matrices.
I cannot determine by looking at the .m file (that is a copy of my code here) what the best approach would be.
file = websave('example3D','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1305150/example3D.m');
type(file)
.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Contour Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!