2010-05-10 3 views
0

사용자가 시뮬레이션 단계를 앞뒤로 진행할 수있는 애니메이션을 만들고 싶습니다.Matlab GUI : 함수 결과 저장 방법 (응용 상태)

애니메이션은 채널 디코딩의 반복 프로세스를 시뮬레이션해야합니다 (수신기가 비트 블록을 수신하고 연산을 수행 한 다음 해당 블록이 패리티 규칙에 해당하는지 확인). 블록이 일치하지 않으면 작업이 다시 수행됩니다 코드가 주어진 규칙에 해당 할 때 프로세스가 마침내 끝납니다).

필자는 디코딩 프로세스를 수행하는 함수를 작성하고 m x n x i 행렬을 반환했습니다. 여기서 m x n은 데이터 블록이고 i는 반복 인덱스입니다. 따라서 데이터를 디코딩하는 데 3 번 반복이 필요한 경우 각 단계가 완료되면 m x n x 3 행렬이 반환됩니다.

GUI (.fig 파일)에서 디코딩 방법을 실행하는 "디코드"버튼을 두었고 사용자가 기록 된 단계의 데이터를 전환 할 수있는 "뒤로"와 "앞으로"버튼이 있습니다 .

"forward"및 "next"버튼을 클릭하여 인덱스를 변경하고 적절한 단계 상태를 가리켜 "decodedData"행렬과 currentStep 값을 전역 변수로 저장했습니다.

응용 프로그램을 디버깅하려고하면 메서드가 디코딩 된 데이터를 반환하지만 "뒤로"및 "다음"을 클릭하려고하면 디코딩 된 데이터가 선언되지 않은 것처럼 보입니다.

누구든지 Matlab GUI에서 구현하고자하는 논리를 설명하기 위해 함수 결과를 액세스 (또는 저장)하는 것이 가능하다는 것을 알고 있습니까?

답변

1

궁극적으로, 이것은 변수 문제의 범위 지정입니다.

전역 변수는 거의 올바른 대답이 아닙니다.

이 동영상은 가이드의 핸들 구조에 대해 설명합니다 http://blogs.mathworks.com/videos/2008/04/17/advanced-matlab-handles-and-other-inputs-to-guide-callbacks/

이 비디오는 GUI를 사이에 변수의 공유에 대해 설명하고 또한 단일 GUI 문제에 적용 할 수 있습니다. http://blogs.mathworks.com/videos/2005/10/03/guide-video-part-two/

1

트릭은 동일한 작업 공간을 공유하도록 중첩 된 기능을 사용하는 것입니다. 나는 이미 example in your last question 시작하기 때문에, 지금은 단순히 추가 해요 GUI가/​​재생뿐만 아니라, 이전 버전과의 대화 앞으로/갈 수 있도록 애니메이션 중지 제어 :

function testAnimationGUI() 
    %# coordinates 
    t = (0:.01:2*pi)';   %# 'fix SO syntax highlight 
    D = [cos(t) -sin(t)]; 

    %# setup a figure and axis 
    hFig = figure('Backingstore','off', 'DoubleBuffer','on'); 
    hAx = axes('Parent',hFig, 'XLim',[-1 1], 'YLim',[-1 1], ... 
       'Drawmode','fast', 'NextPlot','add'); 
    axis(hAx, 'off','square') 

    %# draw circular path 
    line(D(:,1), D(:,2), 'Color',[.3 .3 .3], 'LineWidth',1); 

    %# initialize point 
    hLine = line('XData',D(1,1), 'YData',D(1,2), 'EraseMode','xor', ... 
       'Color','r', 'marker','.', 'MarkerSize',50); 
    %# init text 
    hTxt = text(0, 0, num2str(t(1)), 'FontSize',12, 'EraseMode','xor'); 

    i=0; 
    animation = false; 

    hBeginButton = uicontrol('Parent',hFig, 'Position',[1 1 30 20], ... 
          'String','<<', 'Callback',@beginButton_callback); 
    hPrevButton = uicontrol('Parent',hFig, 'Position',[30 1 30 20], ... 
          'String','<', 'Callback',@previousButton_callback); 
    hNextButton = uicontrol('Parent',hFig, 'Position',[60 1 30 20], ... 
          'String','>', 'Callback',@nextButton_callback); 
    hEndButton = uicontrol('Parent',hFig, 'Position',[90 1 30 20], ... 
          'String','>>', 'Callback',@endButton_callback); 

    hSlider = uicontrol('Parent',hFig, 'Style','slider', 'Value',1, 'Min',1,... 
         'Max',numel(t), 'SliderStep', [10 100]./numel(t), ... 
         'Position',[150 1 300 20], 'Callback',@slider_callback); 

    hPlayButton = uicontrol('Parent',hFig, 'Position',[500 1 30 20], ... 
          'String','|>', 'Callback',@playButton_callback); 
    hStopButton = uicontrol('Parent',hFig, 'Position',[530 1 30 20], ... 
          'String','#', 'Callback',@stopButton_callback); 

    %#----------- NESTED CALLBACK FUNCTIONS ----------------- 
    function beginButton_callback(hObj,eventdata) 
     updateCircle(1) 
    end 

    function endButton_callback(hObj,eventdata) 
     updateCircle(numel(t)) 
    end 
    function nextButton_callback(hObj,eventdata) 
     i = i+1; 
     if (i > numel(t)), i = 1; end 
     updateCircle(i) 
    end 

    function previousButton_callback(hObj,eventdata) 
     i = i-1; 
     if (i < 1), i = numel(t); end 
     updateCircle(i) 
    end 

    function slider_callback(hObj, eventdata) 
     i = round(get(gcbo,'Value')); 
     updateCircle(i) 
    end 

    function playButton_callback(hObj, eventdata) 
     animation = true; 
     while animation 
      i = i+1; 
      if (i > numel(t)), i = 1; end 
      updateCircle(i) 
     end 
    end 

    function stopButton_callback(hObj, eventdata) 
     animation = false; 
    end 

    function updateCircle(idx) 
     set(hSlider, 'Value', rem(idx-1,numel(t))+1) %# update slider to match 

     set(hLine,'XData',D(idx,1), 'YData',D(idx,2)) %# update X/Y data 
     set(hTxt,'String',num2str(t(idx)))   %# update angle text 
     drawnow          %# force refresh 
     if ~ishandle(hAx), return; end    %# check valid handle 
    end 
    %#------------------------------------------------------- 
end 

당신은 슬라이더 기능 비트 버그를 찾을 수 있습니다를, 그러나 당신은 아이디어를 얻는다.