Problem performing calculation with meshgrid variables

8 ビュー (過去 30 日間)
Joe
Joe 2015 年 9 月 23 日
コメント済み: Joe 2015 年 9 月 23 日
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 ./
  1 件のコメント
Joe
Joe 2015 年 9 月 23 日
great, thankyou! I had a feeling it was a simple solution but I just wasn't seeing it

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by