How to plot a slice of the focal point in the radial direction.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
JOHN
el 26 de Jun. de 2024
Editada: Star Strider
el 26 de Jun. de 2024
I have energy intensity data from an FDTD simulation of a multilevel diffractive lens. Below is the MATLAB code I use to create a normalized intensity distribution, showing how the intensity of light varies with distance from a reference point (MDL) and radial distance:
dataset_er_r = '/er.r'; % Select dataset within the selected h5 file
dataset_er_i = '/er.i'; % Select dataset within the selected h5 file
data_er_r = h5read('fdtd_wvl_0.532_1-er-000200.00.h5', dataset_er_r); % Read HDF5 file
data_er_i = h5read('fdtd_wvl_0.532_1-er-000200.00.h5', dataset_er_i); % Read HDF5 file
data_er = abs(sqrt((data_er_r).^2+(data_er_i).^2));
data_Ir = (data_er.^2)/2;
data_Ir_norm = data_Ir./max(max(data_Ir));
data_Ir_norm2 = vertcat(flipud(data_Ir_norm),data_Ir_norm);
% Show intensity distribution
imagesc(data_Ir_norm2); colormap jet; colorbar; clim([0 1]);
set(gcf,'Position',[300,300,1000,1000]);
title('wavelength = 532 nm', 'FontSize', 80);
xlabel('Distance from FZP (um)', 'FontSize', 40);
ylabel('R (um)', 'FontSize', 40);
set(gca, 'FontSize', 40); % Set axis font size
set(gca, 'TickLabelInterpreter', 'none', 'FontSize', 20); % Increase tick label font size
num_points = size(data_Ir_norm2, 2);
xticks(linspace(1, num_points, 5)); % 7 tick marks for 0, 10, 20, 30, 40, 50, 60
xticklabels({'0','5', '10', '15', '20'});
yticks(linspace(1, size(data_Ir_norm2, 1), 6));
yticklabels(linspace(-50, 50, 6));
This creates this plot:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1723291/image.png)
This code creates a plot to show the focal points. I would like to alter the code so that it shows a slice in the radial direction where the focal point is brightest. Being new to MATLAB, I’m unsure how to achieve this or if there is a specific function that can identify the brightest point and plot a slice in the radial direction, similar to the provided example plot.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1723296/image.png)
Any advice or help would be greatly appreciated!
0 comentarios
Respuesta aceptada
Star Strider
el 26 de Jun. de 2024
Editada: Star Strider
el 26 de Jun. de 2024
This is probably straightforward, and only requires getting the data in the second plot image at the 0 value in either direction, and then plotting it in a separate figure.
The problem I’m having is in getting the data from your .zip file. I don’t se anything that corresponds to 'er' or anything similar to it. (My apologies for not being more familiar with h5 files. I just don’t have occasion to work with them.)
Uz = unzip('fdtd_wvl_0.532_1-er-000200.00.h5.zip')
info = h5info(Uz{1})
data_er_r = h5read(info.Filename,'/er.r');
data_er_i = h5read(info.Filename,'/er.i');
% dataset_er_r = '/er.r'; % Select dataset within the selected h5 file
% dataset_er_i = '/er.i'; % Select dataset within the selected h5 file
% data_er_r = h5read('/pathto/fdtd_wvl_0.532_1-er-000200.00.h5', dataset_er_r); % Read HDF5 file
% data_er_i = h5read('/pathto/fdtd_wvl_0.532_1-out/fdtd_wvl_0.532_1-er-000200.00.h5', dataset_er_i); % Read HDF5 file
data_er = abs(sqrt((data_er_r).^2+(data_er_i).^2));
data_Ir = (data_er.^2)/2;
%data_Iz = (abs(data_ez)).^2;
data_Ir_norm = data_Ir./max(max(data_Ir));
data_Ir_norm2 = vertcat(flipud(data_Ir_norm),data_Ir_norm);
% Show intensity distribution
imagesc(data_Ir_norm2); colormap jet; colorbar; clim([0 1]);
set(gcf,'Position',[300,300,1000,1000]);
title('wavelength = 532 nm', 'FontSize', 80);
xlabel('Distance from FZP (um)', 'FontSize', 40);
ylabel('R (um)', 'FontSize', 40);
set(gca, 'FontSize', 40); % Set axis font size
set(gca, 'TickLabelInterpreter', 'none', 'FontSize', 20); % Increase tick label font size
num_points = size(data_Ir_norm2, 2);
xticks(linspace(1, num_points, 5)); % 7 tick marks for 0, 10, 20, 30, 40, 50, 60
xticklabels({'0','5', '10', '15', '20'});
yticks(linspace(1, size(data_Ir_norm2, 1), 6));
yticklabels(linspace(-50, 50, 6));
EDIT — (26 Jun 2024 at 19:21)
I needed to use the info.Filename in the h5read calls, then it worked. I’m not getting the second plot, however using the information in the only plot that I have, and plotting that matrix as a surf plot (that makes this easier for me to visualise the data) —
[maxv,idx] = max(data_Ir_norm2,[],'all')
[r,c] = ind2sub(size(data_Ir_norm2), idx)
figure
surfc(data_Ir_norm2, 'EdgeColor','interp')
colormap(turbo)
colorbar
xlabel('columns')
ylabel('rows')
Irvc = data_Ir_norm2(:,c);
figure
plot(Irvc)
grid
xlabel('rows')
title(sprintf('Slice Across Rows at Column %d',c))
Irvr = data_Ir_norm2(r,:);
figure
plot(Irvr)
grid
xlabel('columns')
title(sprintf('Slice Across Columns at Row %d',r))
Do something similar with the second plot, if necessary (if the ‘Slice Across Rows’ plot is not what you want). Use tthe max and ind2sub functions to return the appropriate values in that plot, as I did here. I will do something similar tto this with the data in the second plot if I havbe the code for that plot.
.
Más respuestas (0)
Ver también
Categorías
Más información sobre Blue 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!