Matlab GUI

di il
3 risposte

Matlab GUI

Salve a tutti, sono nuovo di questo forum. Sto imparando ora a programmare le GUI su matlab e quindi mi chiedevo se possiate darmi una mano. Il mio problema è il seguente: ho creato questa interfaccia tramite il comando "guide".
Ora quello che vorrei fare è questo: seleziono dal pannello uno di questi tre checkbox e, dopo aver premuto il pulsante, deve plottare sull'Axis. Ho scritto tre script, ognuno per il plottaggio diverso. Vi allego anche il codice che ho scritto ma mi da errore. Ora ho trovato una guida sul sito di matlab ma non riesco a venire a capo della soluzione. Qualcuno vorrebbe darmi una mano per favore? Grazie mille.
function varargout = prova(varargin)
% PROVA MATLAB code for prova.fig
%      PROVA, by itself, creates a new PROVA or raises the existing
%      singleton*.
%
%      H = PROVA returns the handle to a new PROVA or the handle to
%      the existing singleton*.
%
%      PROVA('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in PROVA.M with the given input arguments.
%
%      PROVA('Property','Value',...) creates a new PROVA or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before prova_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to prova_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help prova

% Last Modified by GUIDE v2.5 10-Jun-2018 16:29:06

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @prova_OpeningFcn, ...
                   'gui_OutputFcn',  @prova_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before prova is made visible.
function prova_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to prova (see VARARGIN)

% Choose default command line output for prova
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes prova wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = prova_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


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

cb_1 = get(hObject.plot1,'value');
% Hint: get(hObject,'Value') returns toggle state of plot1


% --- Executes on button press in plot2.
function plot2_Callback(hObject, eventdata, handles)
% hObject    handle to plot2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
cb_2 = get(hObject.plot2,'value');
% Hint: get(hObject,'Value') returns toggle state of plot2


% --- Executes on button press in plot3.
function plot3_Callback(hObject, eventdata, handles)
% hObject    handle to plot3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
cb_3 = get(hObject.plot3,'value');
% Hint: get(hObject,'Value') returns toggle state of plot3


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

%cb_1 = get(hObject.plot1,'value');
%cb_2 = get(hObject.plot2,'value');
%cb_3 = get(hObject.plot3,'value');

if(cb_1)
    p_1.m
end
if(cb_2)
    p_2.m
end
if(cb_3)
    p_3.m
end

3 Risposte

  • Re: Matlab GUI

    Ho risolto il problema riguardante il button_Callback() però non riesco a far plottare quel che voglio nell'apposita area. Chiedo aiuto per favore.
  • Re: Matlab GUI

    Se hai modificato il codice che hai inserito nella domanda precedente, dovresti pubblicare la versione aggiornata.

    Immagino che le istruzioni per il plottaggio siano nei files "p_1.m" ecc.: se è così dovresti anche loro (o almeno uno di essi, se sono "simili").
    Non ti si può aiutare, se non pubblichi il codice.

    Dovresti anche chiarire cosa intendi con però non riesco a far plottare quel che voglio nell'apposita area: ottieni un messaggio di errore?
  • Re: Matlab GUI

    Ciao scusate il ritardo. Si effettivamente il codice del plottaggio sta all'interno degli script "ES: p_1.m". Ora vi carico il codice come l 'ho modificato per risolvere il problema delle call_back().

    -> Cerco di essere piu chiaro alla domanda: "Dovresti anche chiarire cosa intendi con però non riesco a far plottare quel che voglio nell'apposita area: ottieni un messaggio di errore?"
    Io vorrei che, dopo aver creato nella GUI l'area apposita per il plottaggio, dopo aver mandato in exec con la callback del pulsante lo script, il plot della mia funzione venga visualizzato non su una finestra generica come di solito fa matlab, ma bensi sull'interfaccia grafica stessa.

    Spero stavolta di essermi fatto capire.
    function varargout = prova(varargin)
    %PROVA MATLAB code file for prova.fig
    %      PROVA, by itself, creates a new PROVA or raises the existing
    %      singleton*.
    %
    %      H = PROVA returns the handle to a new PROVA or the handle to
    %      the existing singleton*.
    %
    %      PROVA('Property','Value',...) creates a new PROVA using the
    %      given property value pairs. Unrecognized properties are passed via
    %      varargin to prova_OpeningFcn.  This calling syntax produces a
    %      warning when there is an existing singleton*.
    %
    %      PROVA('CALLBACK') and PROVA('CALLBACK',hObject,...) call the
    %      local function named CALLBACK in PROVA.M with the given input
    %      arguments.
    %
    %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
    %      instance to run (singleton)".
    %
    % See also: GUIDE, GUIDATA, GUIHANDLES
    
    % Edit the above text to modify the response to help prova
    
    % Last Modified by GUIDE v2.5 10-Jun-2018 18:22:04
    
    % Begin initialization code - DO NOT EDIT
    gui_Singleton = 1;
    gui_State = struct('gui_Name',       mfilename, ...
                       'gui_Singleton',  gui_Singleton, ...
                       'gui_OpeningFcn', @prova_OpeningFcn, ...
                       'gui_OutputFcn',  @prova_OutputFcn, ...
                       'gui_LayoutFcn',  [], ...
                       'gui_Callback',   []);
    if nargin && ischar(varargin{1})
       gui_State.gui_Callback = str2func(varargin{1});
    end
    
    if nargout
        [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
    else
        gui_mainfcn(gui_State, varargin{:});
    end
    % End initialization code - DO NOT EDIT
    
    
    % --- Executes just before prova is made visible.
    function prova_OpeningFcn(hObject, eventdata, handles, varargin)
    % This function has no output args, see OutputFcn.
    % hObject    handle to figure
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    % varargin   unrecognized PropertyName/PropertyValue pairs from the
    %            command line (see VARARGIN)
    
    % Choose default command line output for prova
    handles.output = hObject;
    
    % Update handles structure
    guidata(hObject, handles);
    
    % UIWAIT makes prova wait for user response (see UIRESUME)
    % uiwait(handles.figure1);
    
    
    % --- Outputs from this function are returned to the command line.
    function varargout = prova_OutputFcn(hObject, eventdata, handles)
    % varargout  cell array for returning output args (see VARARGOUT);
    % hObject    handle to figure
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    
    % Get default command line output from handles structure
    varargout{1} = handles.output;
    
    
    % --- Executes during object creation, after setting all properties.
    function figure1_CreateFcn(hObject, eventdata, handles)
    % hObject    handle to figure1 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    empty - handles not created until after all CreateFcns called
    
    
    % --- Executes during object creation, after setting all properties.
    function axes1_CreateFcn(hObject, eventdata, handles)
    % hObject    handle to axes1 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    empty - handles not created until after all CreateFcns called
    
    % Hint: place code in OpeningFcn to populate axes1
    
    
    % --- Executes on button press in plot1.
    function plot1_Callback(hObject, eventdata, handles)
    % hObject    handle to plot1 (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 plot1
    
    
    % --- Executes on button press in plot2.
    function plot2_Callback(hObject, eventdata, handles)
    % hObject    handle to plot2 (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 plot2
    
    
    % --- Executes on button press in plot3.
    function plot3_Callback(hObject, eventdata, handles)
    % hObject    handle to plot3 (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 plot3
    
    
    % --- Executes on button press in selectButton.
    function selectButton_Callback(hObject, eventdata, handles)
    % hObject    handle to selectButton (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    
    cb_1 = get(handles.plot1,'Value');
    cb_2 = get(handles.plot2,'Value');
    cb_3 = get(handles.plot3,'Value');
    
    if(cb_1)
        p_1
    end
    if(cb_2)
       p_2
    end
    if(cb_3)
        p_3
    end
    
Devi accedere o registrarti per scrivere nel forum
3 risposte