Matlab Edit Text

myto27 -  
karirovax Messages postés 3584 Statut Membre -
Bonjour,

J'ai créé une interface graphique à l'aide du GUI de Matlab. Sur cette interface graphique se trouve une case "Edit Text" dans la quelle un utilisateur peut rentrer une valeur de type double. J'aimerais bien me servir ensuite de cette valeur Dans le Call Back d'un Push Button pour effectuer un calcul.

Est ce que quelqu'un pourrait me dire comment faire pour récupérer cette valeur dans le Call Back du Edit Text et s'en servir dans le Call Back du Push Button?

Merci d'avance

2 réponses

  1. karirovax Messages postés 3584 Statut Membre 215
     
    salut

    utilisez la commande:

    num2str et str2num

    donc le reste est claire ;)
    0
    1. myto27
       
      Salut et merci pour votre réponse,

      J'ai déjà utilisé cette fonction. Précisément de cette facon:

      ValRadius = str2double(get(hObject,'String'));

      Le problème c'est que je n'arrive pas à me servir de cette valeur lue dans le callback du Edit Text(RadiusWert - voir cidessous) pour mener un calcul dans le Call Back du Push Button.


      En plus clair ma question est de savoir comment sauvegarder la valeur d'un Edit Text de telle sorte qu'on puisse s'en servir plus loin dans le Call Back d'un Push Button??

      Merci

      function RadiusWert_Callback(hObject, eventdata, handles)
      % hObject handle to RadiusWert (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles structure with handles and user data (see GUIDATA)

      %Beginn Diplomarbeit Stephane Nkamgnia 2011
      %Bewertung der gewählten Leiterschleife
      ValRadius = str2double(get(hObject,'String'));
      if isnan(ValRadius)
      errordlg('You must enter a numeric value','Bad Input','modal')
      end
      handels.Radius=ValRadius;
      % ICE MANNHEIM hObject=ValRadius;

      guidata(hObject,handles)function RadiusWert_Callback(hObject, eventdata, handles)
      % hObject handle to RadiusWert (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles structure with handles and user data (see GUIDATA)

      %Beginn Diplomarbeit Stephane Nkamgnia 2011
      %Bewertung der gewählten Leiterschleife
      ValRadius = str2double(get(hObject,'String'));
      if isnan(ValRadius)
      errordlg('You must enter a numeric value','Bad Input','modal')
      end
      handels.Radius=ValRadius;
      % ICE MANNHEIM hObject=ValRadius;

      guidata(hObject,handles)
      0
    2. karirovax Messages postés 3584 Statut Membre 215
       
      Re:

      puisque j'ai pas beaucoup de temps je vous donne mon exemple qui concerne le call back avec la commande str2num et num2str et il vous suffit de faire la même procedure ;)

      http://www.cijoint.fr/cjlink.php?file=cj201105/cij7GYkmTM.zip
      0
    3. karirovax Messages postés 3584 Statut Membre 215
       
      Re:

      des nouvelles ??

      essayez la procedure qui je te donne dans le lien:

      http://www.cijoint.fr/cjlink.php?file=cj201105/cij7GYkmTM.zip
      0
    4. karirovax Messages postés 3584 Statut Membre 215
       
      Re:

      si le problème est résolu donc merci de le marquer comme résolu ;)
      0
    5. myto27
       
      Dans les liens que tu m'envoies il y a plusieurs fichiers .m

      Je ne sais pas lequel utiliser et mon problème n'est pas résolu!! Voilà mes lignes de code:


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

      % Last Modified by GUIDE v2.5 24-May-2011 19:08:44

      % Begin initialization code - DO NOT EDIT
      gui_Singleton = 1;
      gui_State = struct('gui_Name', mfilename, ...
      'gui_Singleton', gui_Singleton, ...
      'gui_OpeningFcn', @FeldstaerkeBerechnungWindowKreisfoermig_OpeningFcn, ...
      'gui_OutputFcn', @FeldstaerkeBerechnungWindowKreisfoermig_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 FeldstaerkeBerechnungWindowKreisfoermig is made visible.
      function FeldstaerkeBerechnungWindowKreisfoermig_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 FeldstaerkeBerechnungWindowKreisfoermig (see VARARGIN)

      %Beginn Diplomarbeit Stephane Nkamgnia 2011

      %Ende Diplomarbeit Stephane Nkamgnia 2011

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

      % Update handles structure
      guidata(hObject, handles);

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


      % --- Outputs from this function are returned to the command line.
      function varargout = FeldstaerkeBerechnungWindowKreisfoermig_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;



      function WiderstandOhmWert_Callback(hObject, eventdata, handles)
      % hObject handle to WiderstandOhmWert (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles structure with handles and user data (see GUIDATA)

      %Beginn Diplomarbeit Stephane Nkamgnia 2011
      %Bewertung der gewählten Leiterschleife
      ValWiderstandOhm = str2double(get(hObject,'String'));
      if isnan(ValWiderstandOhm)
      errordlg('Sie sollen ein numerisches Wert angeben','Bad Input','modal')
      end

      guidata(hObject,handles)


      %Ende Diplomarbeit Stephane Nkamgnia 2011

      % Hints: get(hObject,'String') returns contents of WiderstandOhmWert as text
      % str2double(get(hObject,'String')) returns contents of WiderstandOhmWert as a double


      % --- Executes during object creation, after setting all properties.
      function WiderstandOhmWert_CreateFcn(hObject, eventdata, handles)
      % hObject handle to WiderstandOhmWert (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles empty - handles not created until after all CreateFcns called

      % Hint: edit controls usually have a white background on Windows.
      % See ISPC and COMPUTER.
      if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
      set(hObject,'BackgroundColor','white');
      end



      function RadiusWert_Callback(hObject, eventdata, handles)
      % hObject handle to RadiusWert (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles structure with handles and user data (see GUIDATA)

      %Beginn Diplomarbeit Stephane Nkamgnia 2011
      %Bewertung der gewählten Leiterschleife
      ValRadius = str2double(get(hObject,'String'));
      if isnan(ValRadius)
      errordlg('Sie sollen ein numerisches Wert angeben','Bad Input','modal')
      end

      guidata(hObject,handles)


      %Ende Diplomarbeit Stephane Nkamgnia 2011

      % Hints: get(hObject,'String') returns contents of RadiusWert as text
      % str2double(get(hObject,'String')) returns contents of RadiusWert as a double


      % --- Executes during object creation, after setting all properties.
      function RadiusWert_CreateFcn(hObject, eventdata, handles)
      % hObject handle to RadiusWert (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles empty - handles not created until after all CreateFcns called

      % Hint: edit controls usually have a white background on Windows.
      % See ISPC and COMPUTER.
      if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
      set(hObject,'BackgroundColor','white');
      end





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


      %Beginn Diplomarbeit Stephane Nkamgnia 2011

      %Berechnung der Feldstärke in Abhängigkeit der Leitungsquerschnitt bei
      %einem kreisförmigen Leiterschleife

      %Bekannt sind folgende Grösse:


      %R: Ohmschen Widerstand der Leiterschleife[Ohm]
      ROhmString=get(handels.WiderstandOhmWert, 'String');
      ROhm=str2double(ROhmString);
      %f: Frequenz [Hz]
      f=50;
      %zeitspanne
      T=1/f;
      %omega: Kreisfrequenz [rad/s]
      w=2*pi*f;
      %phiuc: Nullphasenwinkel
      phiuc=0;
      %U: Amplitude der Spannung
      U=230;
      %phiic: Nullphasenwinkel
      phiic=0;
      %Ic: Amplitude des Stromes
      Ic=10;
      %Deltat: Zeitspanne
      Deltat=T;

      %r: Maximaler Radius der Leiterschleife

      rString = get(handles.RadiusWert,'String');
      r=str2double(rString);

      m=1;
      s=0.1;
      for n=0:s:r

      %A:Fläche
      A=pi*n^2;
      %C1: Konstante
      C1=Deltat/A;
      %B: Magnetisches Feld
      Beff=1/2*(-1/(T*w)*(C1^2*(-U^2*sin(2*phiuc)+2*U*R*Ic*sin(phiuc+phiic)-R^2*Ic^2*sin(2*phiic)-2*U^2*T*w+U^2*sin(2*w*T+2*phiuc)+4*U*R*Ic*cos(-phiuc+phiic)*T*w-2*U*R*Ic*sin(2*w*T+phiuc+phiic)-2*R^2*Ic^2*T*w+R^2*Ic^2*sin(2*w*T+2*phiic))))^(1/2);

      VectorBeff(m)=Beff;
      VectorRadius(m)=n;

      m=m+1;
      end

      VectorSizeVectorRadius=size(VectorRadius);
      xx=1:1:VectorSizeVectorRadius(1,2);
      x=0:s:r;
      y=VectorBeff(xx);
      plot(x,y)

      %Ende Diplomarbeit Stephane Nkamgnia 2011



      function edit3_Callback(hObject, eventdata, handles)
      % hObject handle to edit3 (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles structure with handles and user data (see GUIDATA)

      % Hints: get(hObject,'String') returns contents of edit3 as text
      % str2double(get(hObject,'String')) returns contents of edit3 as a double


      % --- Executes during object creation, after setting all properties.
      function edit3_CreateFcn(hObject, eventdata, handles)
      % hObject handle to edit3 (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles empty - handles not created until after all CreateFcns called

      % Hint: edit controls usually have a white background on Windows.
      % See ISPC and COMPUTER.
      if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
      set(hObject,'BackgroundColor','white');
      end



      function edit4_Callback(hObject, eventdata, handles)
      % hObject handle to edit4 (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles structure with handles and user data (see GUIDATA)

      % Hints: get(hObject,'String') returns contents of edit4 as text
      % str2double(get(hObject,'String')) returns contents of edit4 as a double


      % --- Executes during object creation, after setting all properties.
      function edit4_CreateFcn(hObject, eventdata, handles)
      % hObject handle to edit4 (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles empty - handles not created until after all CreateFcns called

      % Hint: edit controls usually have a white background on Windows.
      % See ISPC and COMPUTER.
      if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
      set(hObject,'BackgroundColor','white');
      end



      function edit5_Callback(hObject, eventdata, handles)
      % hObject handle to edit5 (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles structure with handles and user data (see GUIDATA)

      % Hints: get(hObject,'String') returns contents of edit5 as text
      % str2double(get(hObject,'String')) returns contents of edit5 as a double


      % --- Executes during object creation, after setting all properties.
      function edit5_CreateFcn(hObject, eventdata, handles)
      % hObject handle to edit5 (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles empty - handles not created until after all CreateFcns called

      % Hint: edit controls usually have a white background on Windows.
      % See ISPC and COMPUTER.
      if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
      set(hObject,'BackgroundColor','white');
      end



      function edit6_Callback(hObject, eventdata, handles)
      % hObject handle to edit6 (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles structure with handles and user data (see GUIDATA)

      % Hints: get(hObject,'String') returns contents of edit6 as text
      % str2double(get(hObject,'String')) returns contents of edit6 as a double


      % --- Executes during object creation, after setting all properties.
      function edit6_CreateFcn(hObject, eventdata, handles)
      % hObject handle to edit6 (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles empty - handles not created until after all CreateFcns called

      % Hint: edit controls usually have a white background on Windows.
      % See ISPC and COMPUTER.
      if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
      set(hObject,'BackgroundColor','white');
      end



      function edit7_Callback(hObject, eventdata, handles)
      % hObject handle to edit7 (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles structure with handles and user data (see GUIDATA)

      % Hints: get(hObject,'String') returns contents of edit7 as text
      % str2double(get(hObject,'String')) returns contents of edit7 as a double


      % --- Executes during object creation, after setting all properties.
      function edit7_CreateFcn(hObject, eventdata, handles)
      % hObject handle to edit7 (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles empty - handles not created until after all CreateFcns called

      % Hint: edit controls usually have a white background on Windows.
      % See ISPC and COMPUTER.
      if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
      set(hObject,'BackgroundColor','white');
      end



      function edit8_Callback(hObject, eventdata, handles)
      % hObject handle to edit8 (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles structure with handles and user data (see GUIDATA)

      % Hints: get(hObject,'String') returns contents of edit8 as text
      % str2double(get(hObject,'String')) returns contents of edit8 as a double


      % --- Executes during object creation, after setting all properties.
      function edit8_CreateFcn(hObject, eventdata, handles)
      % hObject handle to edit8 (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles empty - handles not created until after all CreateFcns called

      % Hint: edit controls usually have a white background on Windows.
      % See ISPC and COMPUTER.
      if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
      set(hObject,'BackgroundColor','white');
      end



      function edit9_Callback(hObject, eventdata, handles)
      % hObject handle to edit9 (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles structure with handles and user data (see GUIDATA)

      % Hints: get(hObject,'String') returns contents of edit9 as text
      % str2double(get(hObject,'String')) returns contents of edit9 as a double


      % --- Executes during object creation, after setting all properties.
      function edit9_CreateFcn(hObject, eventdata, handles)
      % hObject handle to edit9 (see GCBO)
      % eventdata reserved - to be defined in a future version of MATLAB
      % handles empty - handles not created until after all CreateFcns called

      % Hint: edit controls usually have a white background on Windows.
      % See ISPC and COMPUTER.
      if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
      set(hObject,'BackgroundColor','white');
      end
      0
  2. nastouille74
     
    J'ai la même question ! Vos liens sont broken, pouvez vous en mettre de nouveaux que je puisse comprendre SVP

    Merci d'avance
    0
    1. karirovax Messages postés 3584 Statut Membre 215
       
      Salut

      Oui le lien est mort maintenant, je vous donne un autre " pour vous :) "

      https://mon-partage.fr/f/bywmaj1q/
      0