How to automatically determine grid size for a dataset?
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a loop that solves an equation using different values of parameters each time, which basically generates a new set of data for each iteration. I want to make a contour plot for each set of data but the problem is, I'd have to change the grid size every time to get the correct contours. Is there a way to automatically adjust the mesh, perhaps based on the maximum and minimum values in each dataset?
댓글 수: 0
답변 (1개)
Nandini
2023년 7월 9일
Yes, you can automatically adjust the mesh for contour plots based on the maximum and minimum values in each dataset. MATLAB provides the `caxis` function that allows you to set the color axis limits for the contour plot dynamically.
Here's an example of how you can adjust the mesh for contour plots based on the dataset's maximum and minimum values:
% Example loop that generates different datasets
for i = 1:numIterations
% Generate data for each iteration
data = generateData(i); % Replace with your own data generation code
% Create contour plot
figure;
contour(data);
% Adjust the mesh based on the maximum and minimum values in the dataset
caxis([min(data(:)), max(data(:))]);
% Add labels, title, etc. to the plot
xlabel('X');
ylabel('Y');
title(['Contour Plot - Iteration ', num2str(i)]);
% Other customizations for the plot
% Save the plot if needed
saveas(gcf, ['contour_plot_iteration_', num2str(i), '.png']);
end
In this example, within the loop, you generate a different dataset for each iteration. Then, you create a contour plot using the `contour` function. After that, you adjust the mesh using the `caxis` function by setting the color axis limits to the minimum and maximum values of the dataset (`min(data(:))` and `max(data(:))`). This ensures that the contour plot is scaled properly based on the dataset's range.
You can customize the plot further by adding labels, titles, legends, or any other desired customizations. Additionally, you can save the plots if needed using the `saveas` function.
Make sure to replace `generateData(i)` with your own code that generates the dataset for each iteration.
댓글 수: 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!