1

I am looking for help for my particular problem.

I have a contour plot created from XYZ data. This plot contains 2 broad peaks with one more intense than the other.

When the most intense peak is aligned with the Y axis, I can perform a fitting of every YZ curve at each X values. I usually do a gaussian fit to plot the peak center on the same graph.

In some cases I need to perform the same fitting but no along the Y axis direction (in this case I just plot YZ scan at every different X values) but along another arbitrary direction.

For the moment the only way I found is the following: -plot the contour plot and find for the position of the most intense peak -if the position is not aligned with the Y axis, then rotate all the datas and plot again the contour -perform the YZ gaussian fit for every X value - Rotate the resulting XY position to go back to the original plot -plot the XY position as a line on the original contour plot

this is quite long and requires a lot of memory. i would like ot know if there is a more elegant/faster way.

Thanks for your help

David

Dav
  • 65
  • 1
  • 7
  • Sorry I answered to quickly. You answer is very useful but I still lack something. I want to extract the data along each perpendicular directions of the arbitrary line and make a fit on them. I guess that if I know the (x1,y1) (x2,y2) points for my line (let's call it Master line), there should be an easy way to obtain the data along perpendicular lines from this Master line. – Dav Mar 19 '13 at 05:50

1 Answers1

0

I take it you want to extract data from the (x,y,z) data along some arbitrary line in order to make a fit. A contour plot will show only part of the data, the full z(x,y) data can be shown with imagesc etc. Say you want the data along line defined by two points (x1,y1) -> (x2,y2). According to the eq of the line, the line y=a*x+b the slope a is (y2-y1)/(x2-x1) and b=y1-a*x1. For example, I'll select (x,y) coordinates in the following contour:

Create data and end points:

m=peaks(100);
x1=11 ; x2=97;
y1=66; y2=40;

Thus the line parameters are:

a=(y2-y1)/(x2-x1);
b=y1-a*x1;

and the line is:

x=x1:x2;
y=round(a*x+b);

select the proper (x,y) elements using linear indexing:

ind=sub2ind(size(m),y,x)

plot:

subplot(2,1,1)
contour(m,10); hold on
line([x1 x2],[y1 y2],'Color',[1 0 0]);

subplot(2,1,2)
plot(m(ind))

enter image description here

You can now use vec=m(ind) to fit your function.

bla
  • 25,846
  • 10
  • 70
  • 101
  • Sorry I answered to quickly. You answer is very useful but I still lack something. I want to extract the data along each perpendicular directions of the arbitrary line and make a fit on them. I guess that if I know the (x1,y1) (x2,y2) points for my line (let's call it Master line), there should be an easy way to obtain the data along perpendicular lines from this Master line. – Dav Mar 19 '13 at 05:51
  • The answer deals with a line defined between **arbitrary** two points `(x1,y1)->(x2,y2)`. Note that I'm not treating vertical lines (infinite slope), this require some more lines but I'm sure you can handle it. For getting the perpendicular lines see http://stackoverflow.com/questions/1811549/perpendicular-on-a-line-from-a-given-point – bla Mar 19 '13 at 06:26
  • OK thank you for your answer. For the case of vertical line, I just have to look through the XZ line along each Y values. – Dav Mar 19 '13 at 07:15