How to get contour plot of multiple Datas in the same plot?
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Star Strider
2022-11-26
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 个评论
Star Strider
2022-11-27
They of course must agree.
Example —
X1 = 0:0.1:10;
Z1 = X1.*exp(-0.75*X1)
X2 = 0:0.5:20;
Z2 = sin(2*pi*X2*5)
X3 = 0:25;
Z3 = exp(-0.1*X3) .* cos(2*pi*3*X3)
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.
.
另请参阅
类别
在 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!