From: andy a. <aa...@us...> - 2004-12-06 17:38:46
|
Update of /cvsroot/octave/octave-forge/main/plot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5611/main/plot Modified Files: get_graph_data.m Log Message: complete - appears to work Index: get_graph_data.m =================================================================== RCS file: /cvsroot/octave/octave-forge/main/plot/get_graph_data.m,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- get_graph_data.m 6 Dec 2004 16:19:17 -0000 1.1 +++ get_graph_data.m 6 Dec 2004 17:38:24 -0000 1.2 @@ -29,30 +29,61 @@ usage('get_graph_data( xaxis, yaxis )'); end -printf('click (with mouse #1) x axis points, then (mouse #2)\n'); -fflush(stdout); -[xa_x,xa_y]= grab(); -if length(xa_x) ~= length(xaxis) - error(sprintf('You specified %d xaxis points, but entered %d', ... - length(xaxis), length(xa_x) )); -end -x_islog= test_log( xa_x, xa_y, xaxis, 'x axis'); +[xa_x, xa_y, xa_n, x_islog]= get_ax_points( xaxis, 'x axis'); +[ya_x, ya_y, ya_n, y_islog]= get_ax_points( yaxis, 'y axis'); +% Based on entered points, we want to see if the axis is +% rotated (like in a scanned image, for example +X=[xa_x,xa_y,0*xa_y+1;ya_x,ya_y,0*ya_y+1]; +Y=[xa_n,0*xa_n;0*ya_n,ya_n]; +rot_ax= X\Y; +printf('X axis is at %5.2f degrees\n', ... + 180/pi*atan2( rot_ax(1,2), rot_ax(1,1)) ); +printf('Y axis is at %5.2f degrees\n', ... + 180/pi*atan2( rot_ax(2,2), rot_ax(2,1)) ); -printf('click (with mouse #1) y axis points, then (mouse #2)\n'); +printf('Select points to convert. Press Mouse #2 or #3 to quit\n'); fflush(stdout); -[ya_x,ya_y]= grab(); -if length(ya_x) ~= length(yaxis) - error(sprintf('You specified %d yaxis points, but entered %d', ... - length(yaxis), length(ya_x) )); -end -y_islog= test_log( ya_x, ya_y, yaxis, 'y axis'); +[x,y]= grab(); +dconv= [x,y,x*0+1]*rot_ax; + +x= dconv(:,1); +if x_islog; x= 10.^x; end +y= dconv(:,2); +if y_islog; y= 10.^y; end + +function [a_x, a_y, a_n, islog]= get_ax_points( ax_pts, ax_text); + printf(sprintf( ... + 'click (with mouse #1) %s points, then (mouse #2)\n', ax_text)); + fflush(stdout); + [a_x,a_y]= grab(); + if length(a_x) ~= length(ax_pts) + error(sprintf('You specified %d %s points, but entered %d', ... + ax_text, length(ax_pts), length(a_x) )); + end + islog= test_log( a_x, a_y, ax_pts, ax_text); + if islog + a_n= log10(ax_pts(:)); + else + a_n= ax_pts(:); + end +endfunction -function ll=test_log( dx, dy, dfit, ax_test ) +% Guess at whether axes are linear or logarithmic +function ll=test_log( dx, dy, dfit, ax_text ) if length(dx)<3 - warn(sprintf('Can t test linear or log fit using %d points', ... + printf(sprintf('Warning: Can t test fit using %d points', ... length(dx))) +% try a heuristic test for linear + if any(dfit)==0 || (max(dfit)/min(dfit) < 10) + printf(sprintf('GUESSING axis %s is LINEAR\n', ax_text)); + ll=0; + else + printf(sprintf('GUESSING axis %s is LOGARITHMIC\n', ax_text)); + ll=1; + end + return end dx= dx(:); dy=dy(:); dfit= dfit(:); @@ -69,10 +100,10 @@ dlogfit= min([dlogfit1, dlogfit2]); if dlinfit < dlogfit - printf(sprintf('axis %s is LINEAR\n', ax_test)); + printf(sprintf('axis %s is LINEAR\n', ax_text)); ll=0; else - printf(sprintf('axis %s is LOGARITHMIC\n', ax_test)); + printf(sprintf('axis %s is LOGARITHMIC\n', ax_text)); ll=1; end endfunction |