Hi Omar,
I understand that you are working with a 3D vector field defined on a grid and would like to extract and visualize the Y-component of the field on a specific plane, where one dimension (in this case, y) has a fixed value. The given approach involves trying to plot this as a surface to get a visual representation of the flux through that plane.
Here a few modifications that you can consider adopting in the given MATLAB script:
Fy9800 = (FY(Y == y(n-2)))';
- Floating-point comparison: Using 'Y == y(n-2)' may not behave as intended because of floating-point precision. Even if 'y(n-2)' is exactly 9800 in the vector, comparing it directly like this might not return 'true' due to small numerical differences.
- Indexing structure: This approach treats 'FY' and 'Y' as flat arrays, but if 'FY' is a 3D matrix (n x n x n), this kind of logical indexing can flatten and disrupt the spatial layout. A better and more structured way could be to directly use the known index for 'y = 9800'.
Since the given script utilizes 'linspace(-rmax, rmax, n)' to define the y vector, and since 'y(n-2)' is 9800, we can safely use the following indexing method:
The relevant slice of 'FY' can then be extracted using regular 3D indexing, as shown below:
Fy9800 = squeeze(FY(:, iy, :));
The 'squeeze' function has been used here to remove the singleton Y-dimension and get a 2D matrix of size (n x n) that corresponds to X and Z. Here is how you can align it properly with the plotting grid:
[X2, Z2] = meshgrid(x, z);
The transpose of the 'meshgrid(x, z)' creates matrices where rows correspond to Z and columns to X, and we want 'Fy9800R(i, j)' to correspond to 'Z(i)' and 'X(j)'.
This approach should allow you to create a clear surface plot of the Y-component of your vector field on the specified plane.
For more information regarding various functions used in the above mentioned code snippet, you can refer to the following documentation links: