2d surface or contour plot of three independent variables
15 次查看(过去 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!