2d surface or contour plot of three independent variables
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Özgür Alaydin
el 13 de Oct. de 2022
Comentada: Star Strider
el 24 de Feb. de 2023
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 comentarios
Respuesta aceptada
Star Strider
el 13 de Oct. de 2022
Editada: Star Strider
el 13 de Oct. de 2022
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 comentarios
Harlan Johnson
el 23 de Feb. de 2023
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
el 24 de Feb. de 2023
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)
.
Más respuestas (0)
Ver también
Categorías
Más información sobre Contour Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!