# How to plot a slice of the focal point in the radial direction.

5 views (last 30 days)
JOHN on 26 Jun 2024
Edited: Star Strider on 26 Jun 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 = 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:
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.
Any advice or help would be greatly appreciated!

Star Strider on 26 Jun 2024
Edited: Star Strider on 26 Jun 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')
Uz = 1x1 cell array
{'fdtd_wvl_0.532_1-er-000200.00.h5'}
info = h5info(Uz{1})
info = struct with fields:
Filename: '/users/mss.system.2tw2w/fdtd_wvl_0.532_1-er-000200.00.h5' Name: '/' Groups: [] Datasets: [2x1 struct] Datatypes: [] Links: [] Attributes: []
% 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 = 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')
maxv = 1
idx = 283356
[r,c] = ind2sub(size(data_Ir_norm2), idx)
r = 612
c = 232
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.
.
JOHN on 26 Jun 2024
Use this instead at the beginning to successfuly extract dataset_er_r and data_er_i. Adjust accordingly to match where you have the file saved.
dataset_er_r = '/er.r'; % Select dataset within the selected h5 file
dataset_er_i = '/er.i'; % Select dataset within the selected h5 file

### Categories

Find more on Blue in Help Center and File Exchange

R2024a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!