2009-07-20 6 views
1

いくつかの入力を受け取り、いくつかの機能を実行するGUIを作成しようとしています。私は、ラジオボタンパネルを使用して別のグラフを切り替えることを望みますが、私はちょうどそれを働かせることはできません。ここに私のコードのサンプルがあります。ラジオボタンパネルを使用してさまざまなグラフオプションを選択する

switch get(eventdata.NewValue,'Tag') % Get Tag of selected object 
    case 'button1' 
     status1 = str2double(get(handles.button1,'Value')); 
     if status1 == 1; 
      axes(handles.axes1) 

      grid on; 
      plot(x1,y1) 

     end 
    case 'button2' 
     status2 = str2double(get(handles.button2,'Value')); 
     if status2 == 1; 
      axes(handles.axes1) 

      grid on; 
      plot(x2,y2) 
     end 

    case 'button3' 
     status3 = str2double(get(handles.button3,'Value')); 
     if status3 ==1 
      plot(x3,y3) 
     end 

    otherwise 
     % Code for when there is no match. 

end 
+1

この言語はどのような言語ですか?それをタグに追加すると、より多くの反応が得られます。 –

答えて

0

そうしないといけない理由がない限り、ラジオボタンのコールバックにプロットコードを入れる必要があります。

この大きなスイッチヤードを行う必要はありません。

% --- Executes on button press in radiobutton1. 
function radiobutton1_Callback(hObject, eventdata, handles) 
% hObject handle to radiobutton1 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 

% Hint: get(hObject,'Value') returns toggle state of radiobutton1 
%% 
%get the values of x y into this callback as you see fit 
plot(x,y) 

また、ボタンから出てくる '値'は既にラジオボタンの2倍です。あなたがしているようにそれを変換する必要はありません。

1

this example tutorial on blinkdagger.comと同じようにradio button panelを作成しようとしているようです。具体的には、SelectionChangeFcnを作成してラジオボタンのGUIの変更方法を定義しようとしていると思います。

まず、ラジオボタンが選択されるたびに行を再配置するのではなく、GUIを作成した後、すべての行をプロットして、その行の 'Visible'プロパティを調整することをお勧めします。どのボタンが選択されているかに応じて、線を「オン」または「オフ」にする。あなたのGUIを作るときは、(軸の後に作成され、handles変数に配置された)あなたのコードのどこかにこれらの行を追加することができます。

handles = guidata(hObject); % Retrieve handles structure for GUI 
set(handles.axes1,'NextPlot','add'); % Set axes to allow multiple plots 
lineHandles = [plot(handles.axes1,x1,y1,'Visible','off') ... 
       plot(handles.axes1,x2,y2,'Visible','off') ... 
       plot(handles.axes1,x3,y3,'Visible','off')]; 
handles.lineHandles = lineHandles; % Update handles structure 
guidata(hObject,handles); % Save handles structure 

は、これと同じ軸上のラインの3セットをプロットします。これらの行は最初は表示されず、プロットされた各行のハンドルはベクトル変数 lineHandlesに収集されます。上記の最後の2行はハンドル構造体に行ハンドルを追加し、GUIデータを更新します( hObjectはGUI Figureウィンドウのハンドルにする必要があります)。

さて、あなたはのSelectionChangeFcnために以下のように使用することができます。

handles = guidata(hObject); % Retrieve handles structure for GUI 
buttonTags = {'button1' 'button2' 'button3'}; 
if ~isempty(eventdata.OldValue),   % Check for an old selected object 
    oldTag = get(eventdata.OldValue,'Tag'), % Get Tag of old selected object 
    index = strcmp(oldTag,buttonTags);  % Find index of match in buttonTags 
    set(handles.lineHandles(index),'Visible','off');  % Turn old line off 
end 
newTag = get(eventdata.NewValue,'Tag'), % Get Tag of new selected object 
index = strcmp(newTag,buttonTags);  % Find index of match in buttonTags 
set(handles.lineHandles(index),'Visible','on');   % Turn new line on 
guidata(hObject,handles); % Save handles structure 

注:あなたがプロットされている3つのラインのいずれかを変更したい場合は、単に「のXData」を設定することができますし、いずれかのラインハンドルの 'YData'プロパティ。たとえば、最初のプロットされた線が新しいxとyのデータで更新されます。

set(handles.lineHandles(1),'XData',xNew,'YData',yNew); 
関連する問題