MATLAB: How to get profile coordinates x,y after using improfile

ginputimage analysisimprofileprofileprofile intensity

hi, I try to find a way to get x and y coordinates of my profile after using improfile.
I want to use improfile command to ask user to select a line on the image where he wants a profile intensity and then i want to also get coordinates x and y of this line.
improfile only give me intensity values along the line i trace.
i also know [x,y] = ginput to get pixels positions from mouse click but it doesn't draw a line between 2 positions clicking so it's hard to know which line i will study with improfile(I,xi,yi).
Here is an example of a picture i want to study:
Thanks !

Best Answer

What about this
clc,clear
close
figure('windowstyle','docked')
I = imread('image.png');
imshow(I) % show image
h = msgbox('select the profile');
waitfor(h) % wait of "OK" button
p = impoly; % pick points to create improfile
xy = p.getPosition; % get xy data
[cx,cy,c] = improfile(I,xy(:,1),xy(:,2));
ax1 = axes('position',[.6 .2 .3 .3]); % create small window
line(cx,c(:,1,1),'color','r') % plot red channel
line(cx,c(:,1,2),'color','g') % plot green channel
line(cx,c(:,1,3),'color','b') % plot blue channel