How to plot the electric field using when the desired signal is small and there are many data points
1 次查看(过去 30 天)
显示 更早的评论
Problem: I have a large data set (~5gb) that consists of the following information
x - position vector
y - position vector
z - position vector
Ex - value of the electric field evaluted at (x,y,z)
Ey - value of the electric field evaluted at (x,y,z)
Ez - value of the electric field evaluted at (x,y,z)
I wish to recreate this image in matlab because the program I am using cannot handle all of the data it created:
Using
scatter(x,y, [], mag(Ez) , 'filled')
I get the following:
"Cropping" the data by dropping rows that are not within a specific range yields:
As you can see, the image is very fuzzy. Zooming in once more shows the problem:
What I have tried
downsample() - makes it workable, but too many points "washes out" what I need
meshgrid() does not work because I need too much memory, even if I split my vector into 300 rows and thousands of columns and loop over each column
contour() cannot get to work since the third argument (Z) is numerical data
quiver() also cannot get it to work since it wants a matrix as the thrid argument
回答(1 个)
Gautam
2024-9-24
Assuming that you want to plot the magnitude of the z component of the electric field in a 2D space specified by the variables “x” and “y” and all the data is in the form of arrays, you can use the “imagesc” function.
To use the function, you’d have to reshape the “Ez” array in a way that matches the dimension of the 2D space you want to display it in.
In the code below, I have created an array “Ez” and reshaped it into a matrix of the desired dimension.
% Creating the data arrays to reflect the way they might be in your workspace
Ez = peaks(100);
Ez = Ez(:);
x = linspace(-5,5,100);
y = linspace(-5,5,100);
[x,y] = meshgrid(x,y);
x = x(:);
y = y(:);
%reshaping Ez accorging the size of x and y
Ez = reshape(Ez, sqrt(length(x)),[]);
%specifying the axis limits
xAxis = [min(x) max(x)];
yAxis = [min(y) max(y)];
%Displaying the plot
imagesc(xAxis, yAxis,Ez);
This gives the output
You read more about the “imagesc” function in the following MathWorks documentation:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!