How to get contour plot of multiple Datas in the same plot?

1 visualización (últimos 30 días)
Vaswati Biswas
Vaswati Biswas el 26 de Nov. de 2022
Comentada: Star Strider el 27 de Nov. de 2022
I have X axis values [0 10 20 30 40 50 55] and y axis values starting from 300 to 2000 at the interval of 2. I also have seven Z axis values matching the dimension of y axis. I want to have the contour plot of all the datas in the same plot. My code is given below:
[x,y] = meshgrid(X,Y);
z= [Z1,Z2,Z3,Z4,Z5,Z6,Z7];
Z = zeros(length(x),length(y)) ;
for i = 1:length(x)
for j = 1:length(y)
if i==j % z data exist for only for x(n) y(n) location, n = 1,2,3...
Z(i,j) = z(i);
end
end
end
contourf(x,y,Z)
colorbar
But I am not getting the correct result. Kindly help.

Respuestas (1)

Star Strider
Star Strider el 26 de Nov. de 2022
I did something like this recently in Contourf plot of magnitude of transferfunction along trajectory. See if you can adapt that approach to your problem.
  2 comentarios
Vaswati Biswas
Vaswati Biswas el 27 de Nov. de 2022
Thanks for your reply. But In this case one function is plotted but in my case I have different data therefore when I am trying to incoparate this approch I am getting the error "Data dimensions must agree".
Star Strider
Star Strider el 27 de Nov. de 2022
They of course must agree.
You can use interp1 to make their lengths agree.
Example —
X1 = 0:0.1:10;
Z1 = X1.*exp(-0.75*X1)
Z1 = 1×101
0 0.0928 0.1721 0.2396 0.2963 0.3436 0.3826 0.4141 0.4390 0.4582 0.4724 0.4821 0.4879 0.4904 0.4899 0.4870 0.4819 0.4750 0.4666 0.4570 0.4463 0.4347 0.4225 0.4098 0.3967 0.3834 0.3699 0.3564 0.3429 0.3295
X2 = 0:0.5:20;
Z2 = sin(2*pi*X2*5)
Z2 = 1×41
1.0e-13 * 0 0.0061 -0.0122 0.0539 -0.0245 -0.0049 -0.1078 0.0784 -0.0490 0.0196 0.0098 0.2450 -0.2156 -0.0980 -0.1568 0.1274 -0.0980 0.0686 -0.0392 0.0098 0.0196 -0.0490 -0.4900 0.4606 -0.4312 -0.1667 0.1961 0.3430 -0.3136 -0.2843
X3 = 0:25;
Z3 = exp(-0.1*X3) .* cos(2*pi*3*X3)
Z3 = 1×26
1.0000 0.9048 0.8187 0.7408 0.6703 0.6065 0.5488 0.4966 0.4493 0.4066 0.3679 0.3329 0.3012 0.2725 0.2466 0.2231 0.2019 0.1827 0.1653 0.1496 0.1353 0.1225 0.1108 0.1003 0.0907 0.0821
N = 200;
xfcn = @(x) linspace(min(x), max(x), N); % Create Independent Interpolation Variable Vector For Each Vector
Z1m = interp1(X1, Z1, xfcn(X1)); % Interpolate To Same Lengths
Z2m = interp1(X2, Z2, xfcn(X2)); % Interpolate To Same Lengths
Z3m = interp1(X3, Z3, xfcn(X3)); % Interpolate To Same Lengths
figure
contourf([Z1m; Z2m; Z3m])
colormap(turbo)
Here, they’re interpolated to the same length, then (since they’re row vectors in this example), vertically concatenated to create a matrix, and then presented as that matrix to contourf.
.

Iniciar sesión para comentar.

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!

Translated by