- Meshgrid : https://www.mathworks.com/help/matlab/ref/meshgrid.html
- Griddata : https://www.mathworks.com/help/matlab/ref/griddata.html
- Imagesc : https://www.mathworks.com/help/matlab/ref/imagesc.html
- scatteredInterpolant : https://www.mathworks.com/help/matlab/ref/scatteredinterpolant.html
矩阵数据画彩色图以及二维拟合问题
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
背景:我现在有从comsol中导出的电场图的数据,可以处理成三个矩阵,分别为x(横坐标,如1000*1的矩阵),y(纵坐标,如1000*1的矩阵),F(需要最终展示的数据,如1000*1的矩阵),其中x,y,F一一对应,也就是说,(x(1),y(1))对应的数据就是F(1)。另外x矩阵以及y矩阵内元素的顺序不是从小到大或者从大到小,而是乱序的,且不具备等差数列等规律
问题:(1)我想在matlab中画出这个矩阵对应的图,但是用我常用的imagesc、pcolor等方式没有用,并且实际矩阵是比较大的,大概1*17189,所以处理起来也比较麻烦,所以想问问各位有什么更好的办法可以处理这个问题
(2)图画好之后,需要对既有的数据做固定间隔的x以及y方向的插值拟合,想了一下,这种数据貌似传统的interp2也不是很好用,像请教下看有没有什么更好的办法
附件附上了具体的数据
附图截了一小部分的数据:第一列为x,第二列为y,第四列为F,第三列忽略掉就行
0 comentarios
Respuestas (1)
Suraj Kumar
el 31 de Jul. de 2024
Hi feng,
From what I gather, your goal is to visualize a large matrix and subsequently execute interpolation fitting at consistent intervals. To achieve the desired results, you can go through the following steps along with the code snippets:
1. The data consists of three matrices: `x`, `y`, and `F`. These scattered data points are interpolated onto a regular grid for visualization. Grid points are defined using `linspace` and a meshgrid is created with the function `meshgrid`.
xq = linspace(min(x), max(x), 500);
yq = linspace(min(y), max(y), 500);
[Xq, Yq] = meshgrid(xq, yq); % meshgrid for grid points
2. The `griddata` function interpolates the scattered data (`x`, `y`, `F`) onto the grid using the 'cubic' method. The data is then visualized with `imagesc`, including axis adjustments.
figure;
imagesc(xq, yq, Fq);
axis xy;
colorbar;
xlabel('X');
ylabel('Y');
title('Interpolated Data Plot');
3. To perform interpolation fitting, you can create an interpolant object from the scattered data using `scatteredInterpolant`. Then define grid points using `linspace` and create a meshgrid with `meshgrid`.
F_interpolant = scatteredInterpolant(x, y, F, 'linear', 'none');
% Define the grid for interpolation
xq = linspace(min(x), max(x), 500);
yq = linspace(min(y), max(y), 500);
[Xq, Yq] = meshgrid(xq, yq); %meshgrid for grid points
4. Then evaluate the interpolant at these grid points (`Xq`, `Yq`) and finally, visualize the interpolated data using `imagesc`, adjusting the axis with `axis xy’.
Fq = F_interpolant(Xq, Yq); % Evaluate the interpolant at the grid points
figure;
imagesc(xq, yq, Fq);
axis xy;
colorbar;
xlabel('X');
ylabel('Y');
title('Interpolated Data Plot from Interpolant');
You may refer the attached output for better understanding:
Kindly refer to the documentation links as mentioned below:
Happy Coding!
0 comentarios
Ver también
Categorías
Más información sobre Big Data Processing 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!