wgun 发表于 2013-6-29 22:43

为什么手工圆滑曲线部分不成功

function se
global handles
global a;
global b;
global c;
global d;
global ha1;
global ha2;
global hMainFig

%clc
%close all
hMainFig=figure('name','手工圆滑','number','off','menubar','none',...
    'units','normalized','tag','hMainFig');
set(hMainFig,'units','normalized','position',[.2,.2,.6,.6]);
set(hMainFig,'defaultuicontrolfontname','隶书');
set(hMainFig,'defaultuicontrolfontsize',13);
set(hMainFig,'defaultuicontrolunits','normalized');

hAxes=axes('position',[.15,.2,.8,.7]);


b=[1.45829E+02
    1.38841E+02
    1.26428E+02
    1.26685E+02
    1.29584E+02
    1.38322E+02
    1.42670E+02
    6.97490E+01
    1.00166E+02
    1.44230E+02
    1.14989E+02
    1.19405E+02
    1.32245E+02
    1.35919E+02
1.33458E+02
1.32025E+02
1.31339E+02
1.35567E+02
1.36867E+02
1.37972E+02
1.41170E+02
1.48319E+02
1.51382E+02
1.56039E+02
1.64074E+02
1.70963E+02
1.74719E+02
1.77379E+02
1.84034E+02
1.87624E+02
1.92784E+02
1.78992E+02
1.87221E+02
1.84854E+02
1.86131E+02
1.81557E+02
1.81499E+02
1.77094E+02
1.76973E+02
1.67492E+02
1.57153E+02
1.58719E+02
1.47376E+02
1.26563E+02
1.19241E+02
1.15421E+02
1.02704E+02
1.00490E+02
9.68207E+01
8.50081E+01
7.32428E+01
6.71406E+01
5.68262E+01
6.29521E+01
3.88121E+01
3.99925E+01
1.09562E+01
1.93862E+01
1.68555E+01
6.17044E+00];
a=[1.04000E+04
   8.80000E+03
   7.20000E+03
   6.00000E+03
   5.20000E+03
   4.40000E+03
   3.60000E+03
3.00000E+03
2.60000E+03
2.20000E+03
1.80000E+03
1.50000E+03
1.30000E+03
1.10000E+03
9.00000E+02
7.80000E+02
6.40000E+02
5.30000E+02
4.60000E+02
3.90000E+02
3.20000E+02
2.65000E+02
2.29000E+02
1.94000E+02
1.59000E+02
1.32000E+02
1.15000E+02
9.70000E+01
7.90000E+01
6.60000E+01
5.70000E+01
4.90000E+01
4.00000E+01
3.30000E+01
2.75000E+01
2.25000E+01
1.88000E+01
1.62000E+01
1.37000E+01
1.12000E+01
9.40000E+00
8.10000E+00
6.90000E+00
5.60000E+00
4.70000E+00
4.10000E+00
3.40000E+00
2.81000E+00
2.34000E+00
2.03000E+00
1.72000E+00
1.41000E+00
1.17000E+00
1.02000E+00
8.60000E-01
7.00000E-01
5.90000E-01
5.10000E-01
4.30000E-01
3.50000E-01];

assignin('base','aa',a);

ha1=loglog(a,b,'g:+');



set(hMainFig,'pointer','cross');
set(hMainFig,'WindowButtonMotionFcn',@ShowPointData);
hText11=uicontrol(hMainFig,'style','text','position',[.05,.05,.1,.1],'string','x:');
hText12=uicontrol(hMainFig,'style','text','position',[.15,.05,.25,.1],'tag','hText12');
hText21=uicontrol(hMainFig,'style','text','position',[.45,.05,.1,.1],'string','y:');
hText22=uicontrol(hMainFig,'style','text','position',[.55,.05,.25,.1],'tag','hText22');
handles=guihandles(hMainFig);%handles的生成
guidata(hMainFig,handles);
set(hMainFig,'windowButtonDownFcn',@WritePointData);
   
function WritePointData(hObject, eventdata, handles)
%hObject -- the handle to the figure or Callback object
%handles -- structure with handles and user data
global handles;
global a;
global b;
global c;
global d;
global ha1;
global ha2;
global hMainFig
hp=findobj(ha1);
w=gco;
while 1
=ginput(1);
set(hMainFig,'WindowButtonMotionFcn',@ShowPointData);
set(handles.hText12,'string',num2str(xx));
set(handles.hText22,'string',num2str(yy));
assignin('base','xxx',xx);
if s==1
if w==hp(1)

      if 900<=xx<100000
          for j=1:length(a)
    if(abs(xx-a(j))<=100)
      b(j)=yy;
         ha1=loglog(a,b,'g:+');
    end
    end
      elseif 500<=xx<900
          for j=1:length(a)
       if(abs(xx-a(j))<=50)
      b(j)=yy;
         ha1=loglog(a,b,'g:+');
       end
          end
       elseif 260<=xx<500
         for j=1:length(a)
       if(abs(xx-a(j))<=27)
      b(j)=yy;
          ha1=loglog(a,b,'g:+');
       end
         end
       elseif 130<=xx<260
         for j=1:length(a)
       if(abs(xx-a(j))<=13)
      b(j)=yy;
          ha1=loglog(a,b,'g:+');
       end
         end
       elseif 60<=xx<130
         for j=1:length(a)
       if(abs(xx-a(j))<=6)
      b(j)=yy;
         ha1=loglog(a,b,'g:+');
       end
         end
       elseif 20<=xx<60
         for j=1:length(a)
       if(abs(xx-a(j))<=2.5)
      b(j)=yy;
          ha1=loglog(a,b,'g:+');
       end
         end
       elseif 5<=xx<20
         for j=1:length(a)
       if(abs(xx-a(j))<=0.6)
      b(j)=yy;
          ha1=loglog(a,b,'g:+');
       end
         end
       elseif 2.5<=xx<5
         for j=1:length(a)
       if(abs(xx-a(j))<=0.28)
      b(j)=yy;
          ha1=loglog(a,b,'g:+');
       end
         end
       elseif 1.1<=xx<2.5
         for j=1:length(a)
       if(abs(xx-a(j))<=0.12)
      b(j)=yy;
          ha1=loglog(a,b,'g:+');
       end
         end
       elseif 0.3<=xx<1.1
         for j=1:length(a)
       if(abs(xx-a(j))<=0.04)
      b(j)=yy;
          ha1=loglog(a,b,'g:+');
       end
         end
      
end

else
   error('没选到线 ');
end

else s~=1
    break;
end

end
   

function ShowPointData(hObject, eventdata, handles)
p=get(gca,'currentpoint');
if(isempty(findobj('tag','htext')))
   ht=text('tag','htext','string',sprintf('(%g, %g)', p(1), p(3)),'position',);
else
   ht = findobj('tag','htext');
   set(ht,'string',sprintf('(%g, %g)', p(1), p(3)),'position',);
end


以上是手工圆滑曲线的程序,但是在x轴小的点上不能拖动,但在x轴大的点上能成功拖动?

麻烦各位高手解答。

ChaChing 发表于 2013-7-1 00:17

个人水平/时间有限, 仅感觉好复杂看著有些吃力, 真无法细究
不过凭LZ的描述及相应代码, 猜测问题出在类似这些逻辑判断语句
请注意下900<=xx<100000的意思不是这范围内, 而是等同 (900<=xx)<100000
试试xx=800; if 900<=xx<100000, disp('You got it!?'); end
页: [1]
查看完整版本: 为什么手工圆滑曲线部分不成功