What is wrong with my code for obtaining 3D maps?

4 views (last 30 days)
Hi, I have this code of MATLAB for obtaining the number of counts from an Avalanche Photodiode detector (APD) with the NI-DAQ model USB 6211 and an external clock to obtain the counts and after it plots a 3D map with the X and Y position and the counts signal obtained from the APD. My problem is that with this code I am obtaining a distorted map. But I know my set up is ok and I am obtaining the results because I use another code to check the counts response. I would appreciate a lot your help. I attach the code and the image how it should be that I took with another detector and what I am obtaining.
numPointsX = 70;
numPointsY = 70;
xMin = 200;
xMax = 210;
yMin = 200;
yMax = 210;
xValues = linspace(xMin,xMax,numPointsX);
yValues = linspace(yMin,yMax,numPointsY);
observedCounts = zeros(numPointsX,numPointsY,1);
acq_time=0.02;
N = 1;
start(dq,"Continuous")
for k=1:numPointsX
current_x = xValues(k);
disp(sprintf("Line %d over %d",k,numPointsY))
for j=1:numPointsY
current_y = yValues(j);
PIdevice.MOV(['A','B'],[current_x current_y]);
dataIn= read(dq,seconds(acq_time));
n0 = max(dataIn.Dev1_ctr0)-min(dataIn.Dev1_ctr0);
dataCounts = n0/acq_time;
observedCounts(j,k,:) = dataCounts;
end
mapMax = squeeze(max(observedCounts,[],3));
f = figure(2);
imagesc(yValues,xValues,mapMax');
axis image;
end
stop(dq)
How it should be -->
How it is obtaining -->
  1 Comment
Dyuman Joshi
Dyuman Joshi on 7 Jul 2022
Edited: Dyuman Joshi on 28 Sep 2023
X and Y limits along with the scale of the colorbar are not same for both figures.
Change the xlimits and ylimits and then compare.

Sign in to comment.

Answers (1)

Nipun
Nipun on 28 Sep 2023
Hi Adriana,
I understand that you want to change the output plot so that it resembles the given plot. I assume that the your code to generate the data points is correct and you need help with the formatting of the data points.
Perhaps two changes to your plot configuration should fix this issue: changing the xlim and ylim (refer to documentation here). In the reference figure, I can infer that y-axis ranges from 210 to 220, however the scale in the output plot is different. You may use the following code to change axis limits:
ylim([yMin, yMax]);
Additionally, consider changing the scale of the colorbar as well to match the reference image.
Hope this helps.
Regards,
Nipun

Products

Community Treasure Hunt

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

Start Hunting!