Problem performing calculation with meshgrid variables

6 次查看(过去 30 天)
Hi,
I'm a matlab novice - hoping someone can point me in the right direction here!
I'm trying to write a short code to transform pixels from an image captured on a flat x-ray area detector (486x193 pixels, pix width 175microns) at an arbitrary orientation to a sample into a useful system relative to the sample being measured. I want to produce a contour plot of the result.
I'm using meshgrid to create variables X and Y for the x and y positions of pixels on the detector, and performing a calculation given in Hammersley 1995 to give me an equivalent diffraction angle Q2 at any pixel on the detector, using the following code:
%set up Xdim and Ydim parameters, relative to centre pixel x0,y0
x = linspace(1,486,486)
y = linspace(1, 193,193)
w_pix = 175e-3
[X,Y]=meshgrid(x,y)
x0 = 242
y0=108
Xdim = (X - x0)*w_pix
Ydim = (Y-y0)*w_pix
zref = 502
%perform transformation - case 1, detector perpendicular to beam
Q2 = atan(power((power(Xdim,2) + power(Ydim,2))/power(zref,2),0.5))
%perform transformation - case 2, detector rotated 35 deg to detector normal
qtilt_rad = pi*35/180
Q2_tilt = atan(power((power(Xdim*cos(qtilt_rad),2)+power(Ydim,2))/(power(zref+sin(qtilt_rad)*Xdim,2)),0.5))
Of the above 2 cases, the first variable Q2 comes out sized [193,486] as I need it, but for Q2_tilt it is [193,193], which can't be contoured against X and Y. I have no idea why the latter should happen - can anyone help?
Many Thanks,
Joe

采纳的回答

Walter Roberson
Walter Roberson 2015-9-23
Q2_tilt = atan( power( (power( Xdim*cos(qtilt_rad),2) + power(Ydim,2)) ./ (power(zref+sin(qtilt_rad)*Xdim,2)), 0.5));
Difference: / became ./

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by