Posez votre question Signaler

Matlab Edit Text

myto27 - Dernière réponse le 25 mai 2011 à 17:48
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
Lire la suite 

Matlab Edit Text »

7 réponses
Réponse
+0
moins plus
salut

utilisez la commande:

num2str et str2num

donc le reste est claire ;)
karirovax- 24 mai 2011 à 16:48
Re:

si le problème est résolu donc merci de le marquer comme résolu ;)
myto27 - 24 mai 2011 à 20:56
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
karirovax- 25 mai 2011 à 17:48
Re: salut

j'ai travaillé avec matlab6.5 mais pas maintenant l'exemple ci dessus est un test qui j'ai fais il ya 3 ou 4 ans c'est pour cela que je peut pas vérifier votre code ( désolé ) mais je te donne un autre éxemple presque le même et avec moin de fichiers .m

puisque vous dites call back donc il faut qu'il y en a plusieurs fichiers au moin deux 2

voici le deuxième exemple ( c'est un peut claire ) :

http://www.cijoint.fr/cjlink.php?file=cj201105/cijXx0jSMy.zip
Ajouter un commentaire
Ce document intitulé « Matlab Edit Text » issu de CommentCaMarche (www.commentcamarche.net) est mis à disposition sous les termes de la licence Creative Commons. Vous pouvez copier, modifier des copies de cette page, dans les conditions fixées par la licence, tant que cette note apparaît clairement.
Dossier à la une
Passage au tout numérique : quel coût pour les particuliers ?