how to allow user to get an arbitrary line profile from a contourplot
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
lets say we have a slice figure:
[X Y Z]=meshgrid([-2:.1:2],[-2:.1:2],[-2:.1:2]);
f=rand(41,41,41);
slice(X,Y,Z,f,0,[],[])
I want the user to be able to use the cursor to draw a line across the slice profile and have matlab open a second figure and plot values of f along that line.
1 comentario
Patrick Kalita
el 1 de Mayo de 2012
You might want to make your question more specific. Is the question about how to draw the line? How to define the line with the cursor (and what does that mean? Are you selecting one, two, 600 points to define the line?) How to interpolate f long the line?
Respuestas (3)
A
el 3 de Mayo de 2012
5 comentarios
Walter Roberson
el 7 de Mayo de 2012
The video is rendered by flash on that site. Flash is often considered a security risk, and there are now a number of browsers which do not support flash at all.
Sean de Wolski
el 4 de Mayo de 2012
I already gave you code that with a little bit of modification could easily do this. Alternatively, you could take another approach:
Have the axes buttondownfcn make note of the current point and set the windowbuttondownfcn to draw a line from the mouse position to that point, as well as set the buttonupfcn to make a note of the new current point and turn off the windowbuttonmotion function. At this point you now know the two endpoints, you can draw line between them and interpolate to this line as necessary.
4 comentarios
Walter Roberson
el 7 de Mayo de 2012
In such a case, the number of points on the line would be variable, and a grid point that was just barely touched would be given as much output weight as a grid point that was fully traversed. The common method to deal with these difficulties is to choose a constant number of points for the profile, divide the distance up in to equal segments, and then to interp the locations so deduced.
Patrick Kalita
el 8 de Mayo de 2012
What you're asking to do isn't something that's going to have an off-the-shelf solution. You need to build it yourself.
To do it you'll need to learn about things like the Figure window event callbacks, passing data between callbacks, etc. For this specific application, understanding the axes CurrentPoint and data interpolation is also needed.
Here's a toy example that could be a good starting point. I'm sure it doesn't do everything and exactly what you want. But if you can understand what it's doing you should be able to extend it to your application:
function sample
[x,y,z] = peaks;
f = figure( ...
'WindowButtonDownFcn', @onMouseDown, ...
'WindowButtonUpFcn', @onMouseUp, ...
'WindowButtonMotionFcn', @onMouseMove );
a = axes('Parent', f);
pcolor(a,x,y,z);
L = line('XData', [], 'YData', [], 'Parent', a);
setappdata(f, 'MouseIsPressed', false);
setappdata(f, 'LineHandle', L);
setappdata(f, 'AxesHandle', a);
setappdata(f, 'FirstLinePoint', [0 0]);
setappdata(f, 'SurfaceData', {x; y; z});
function onMouseDown(src, evt)
setappdata(src, 'MouseIsPressed', true);
setappdata(src, 'FirstLinePoint', ...
get( getappdata( src, 'AxesHandle' ), 'CurrentPoint' ) );
function onMouseUp(src, evt)
setappdata(src, 'MouseIsPressed', false);
L = getappdata(src, 'LineHandle');
x = get( L, 'XData' );
y = get( L, 'YData' );
set( L, 'XData', [], 'YData', [] );
x_interp_pts = linspace(x(1), x(2), 30);
y_interp_pts = linspace(y(1), y(2), 30);
origdata = getappdata(src, 'SurfaceData');
z_interp = interp2( origdata{1}, origdata{2}, origdata{3}, x_interp_pts, y_interp_pts );
figure;
plot(z_interp, '.-');
function onMouseMove(src, evt)
if getappdata(src, 'MouseIsPressed')
firstPoint = getappdata(src, 'FirstLinePoint');
secondPoint = get( getappdata(src, 'AxesHandle'), 'CurrentPoint' );
set( getappdata(src, 'LineHandle'), ...
'XData', [firstPoint(1) secondPoint(1)], ...
'YData', [firstPoint(3) secondPoint(3)] );
end
0 comentarios
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!