C MATLAB Brauche aus Button eine Wahl

kinimod2010

Cadet 4th Year
Registriert
Sep. 2014
Beiträge
68
Hallo Leute,

Ich habe eine GUI erstellt in Matlab habe jedoch ein Problem. Ich brauche Werte aus einer der 6 Callback (ganz normale Pushbuttons) funktionen um in der OpeningFcn eine Switchanweißung ausführen zu können. kann mir da vl einer weiterhelfen?
 
Zuletzt bearbeitet:
Kannst du das etwas konkretisieren?

Brauchst du ein Ergebnis aus einem des Callbacks? Willst du es für eine andere OpeningFcn nutzen?
 
hallo tut mir leid habe hier ein kleines testprogramm geschrieben

Code:
function varargout = untitled(varargin)
% UNTITLED MATLAB code for untitled.fig
%      UNTITLED, by itself, creates a new UNTITLED or raises the existing
%      singleton*.
%
%      H = UNTITLED returns the handle to a new UNTITLED or the handle to
%      the existing singleton*.
%
%      UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in UNTITLED.M with the given input arguments.
%
%      UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to untitled_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 untitled

% Last Modified by GUIDE v2.5 25-Sep-2014 16:14:09

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @untitled_OpeningFcn, ...
                   'gui_OutputFcn',  @untitled_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 untitled is made visible.
function untitled_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 untitled (see VARARGIN)
global WAHL;
% Choose default command line output for untitled
switch WAHL
    case 1
        set(handles.text1,'String',WAHL);
    case 2
        set(handles.text1,'String',WAHL);
    case 3
        set(handles.text1,'String',WAHL);
    case 4
        set(handles.text1,'String',WAHL);
    case 5
        set(handles.text1,'String',WAHL);
    case 6
end


handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = untitled_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global WAHL;
WAHL=1;


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global WAHL;
WAHL=2;


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global WAHL;
WAHL=3;


% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global WAHL;
WAHL=4;


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global WAHL;
WAHL=5;


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global WAHL;
WAHL=6;

Dabei ist noch eine kleine GUI mit 6 buttons und einem Textfeld.
 
Du kannst in der OpeningFcn keine Werte benutzen, die erst später definiert werden.

Wenn du die Wahl aus dem letzten Programmaufruf haben möchtest, würde ich diese als .mat-Datei speichern.
 
Kann ich die Buttons ihrgendwie ín der startup.m ansprechen?

z.B.:
Code:
set (handles.pushbutton1,'Enable','off');

Lg und Danke für deine schnelle Antwort
 
Ich habe das Einlesen und initiale Befüllen von Dropdowns immer in der OutputFcn gemacht. Da wird z.B. eine mat-Datei ausgeführt und die Werte dann eingetragen.

Da würde ich das an deiner Stelle auch machen, da da die handles auf jeden Fall schon gesetzt sind.
 
ich hab das jetzt so gelöst ich habe es einfach in der startup die WAHL=0; geschrieben und in der case dann ein textfeld gemacht das ausgibt das der benutzer noch was wählen muss.

trotzdem danke für deine hilfe.
 
Zurück
Oben