draw matrix H with “contourf”

조회 수: 1 (최근 30일)
Raphael Biendarra
Raphael Biendarra 2021년 4월 6일
답변: prabhat kumar sharma 2024년 2월 22일
Hi, I want to plot the distribution of matrix H along a plane for the following time instances t=0,0.25,0.5,0.75,1 (5individual figures)
Size of matrix H: 51x19 double
I tried everything from the Mathwork side to draw this contourf plots but nothing worked.
Hope you guys can help me?
  댓글 수: 3
pranay dattani
pranay dattani 2021년 4월 6일
x = 0:0.25:0.5:0.75:1;
y = 1:101;
[X Y] = meshgrid(x, y);
G = X.*f(Y)+0.95*h(Y);
contour(G, [-5 -3 -1 -0.1 0 0.1 1 3 5])

댓글을 달려면 로그인하십시오.

답변 (1개)

prabhat kumar sharma
prabhat kumar sharma 2024년 2월 22일
Hi Raphael,
I understand that you are trying to plot countour at different time instances.
To visualize the distribution of matrix H across various time points, MATLAB's contourf function is an excellent tool for generating filled contour plots. If H is structured as a three-dimensional matrix with the third dimension representing time.
Make sure to adjust the indexing of H(:,:,i) to match the structure of your matrix. If H is organized in a different way, or if you have distinct matrices for each time instance, the indexing will need to be modified to reflect your data's specific arrangement.
you can create individual figures for each specified time instance as follows:
% Assuming H is a 3D matrix of size 51x19x5, where the third dimension is time
% Time instances you want to plot
timeInstances = [0, 0.25, 0.5, 0.75, 1];
% Loop through each time instance
for i = 1:length(timeInstances)
% Select the slice of matrix H at the current time instance
% Assuming the timeInstances correspond to the indices of the third dimension of H
matrixSlice = H(:,:,i);
% Create a new figure
figure;
% Plot the filled contour plot of the matrix slice
contourf(matrixSlice);
% Add color bar to indicate the scale
colorbar;
% Add title and axis labels as needed
title(sprintf('Distribution of H at t=%.2f', timeInstances(i)));
xlabel('X-axis');
ylabel('Y-axis');
% Adjust additional plot settings as desired
end
Countour Plots:
I hope it helps!

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by