ich habe folgendes Problem.
Hier meine M-File, welche wen ich sie durch Matlab starte (rechtslick auf die datei und "run"), funktioniert.
Code:
function cf_ = Programm(varargin) % MYADDER M-file for myAdder.fig % MYADDER, by itself, creates a new MYADDER or raises the existing % singleton*.
%
% H = MYADDER returns the handle to a new MYADDER or the handle to % the existing singleton*.
%
% MYADDER('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in MYADDER.M with the given input arguments.
%
% MYADDER('Property','Value',...) creates a new MYADDER or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before myAdder_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to myAdder_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 myAdder
% Last Modified by GUIDE v2.5 04-Sep-2010 18:30:47
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Programm_OpeningFcn, ...
'gui_OutputFcn', @Programm_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
ifnargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
% --- Executes just before myAdder is made visible. function Programm_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 myAdder (see VARARGIN)
% Choose default command line output for myAdder
handles.output = hObject;
% Update handles structure guidata(hObject, handles);
% UIWAIT makes myAdder wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. functionvarargout = Programm_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 input1_editText_Callback(hObject, eventdata, handles) % hObject handle to input1_editText (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 input1_editText as text % str2double(get(hObject,'String')) returns contents of input1_editText as a double input = get(hObject,'String');
if(isempty(input)) set(hObject,'String','A1:A21') end guidata(hObject, handles);
% --- Executes during object creation, after setting all properties. function input1_editText_CreateFcn(hObject, eventdata, handles) % hObject handle to input1_editText (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. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
function input2_editText_Callback(hObject, eventdata, handles) % hObject handle to input2_editText (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 input2_editText as text % str2double(get(hObject,'String')) returns contents of input2_editText as a double input = get(hObject,'String');
if(isempty(input)) set(hObject,'String','B1:B21') end guidata(hObject, handles);
% --- Executes during object creation, after setting all properties. function input2_editText_CreateFcn(hObject, eventdata, handles) % hObject handle to input2_editText (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. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in add_pushbutton1. function add_pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to add_pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
a = get(handles.input1_editText,'String');
% a and b are variables of Strings type, and need to be converted % to variables of Number type before they can be added together % need to convert the answer back into String type to display it
Time = xlsread('Carreau.xlsx', a);
set(handles.answer_staticText1,'String',Time);
% --- 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)
b = get(handles.input2_editText,'String');
% a and b are variables of Strings type, and need to be converted % to variables of Number type before they can be added together
% need to convert the answer back into String type to display it
Pa = xlsread('Carreau.xlsx', b);
set(handles.answer_staticText2,'String',Pa);
guidata(hObject, handles);
% --- Executes on button press in fit_pushbutton. function fit_pushbutton_Callback(hObject, eventdata, handles) % hObject handle to fit_pushbutton (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
a = get(handles.input1_editText,'String');
Time = xlsread('Carreau.xlsx', a);
b = get(handles.input2_editText,'String');
Pa = xlsread('Carreau.xlsx', b);
%CREATEFIT Create plot of data sets and fits
% CREATEFIT(TIME,PA) % Creates a plot, similar to the plot in the main Curve Fitting Tool, % using the data that you provide as input. You can % use this function with the same data you used with CFTOOL % or with different data. You may want to edit the function to % customize the code and this help message.
%
% Number of data sets: 1 % Number of fits: 1
% Data from data set "Pa vs. Time": % X = Time: % Y = Pa: % Unweighted
% Auto-generated by MATLAB on 03-Sep-2010 01:41:13
% Set up figure to receive data sets and fits
f_ = clf;
figure(f_);
set(f_,'Units','Pixels','Position',[498179688485]);
% Line handles and text for the legend.
legh_ = [];
legt_ = {};
% Limits of the x-axis.
xlim_ = [Inf -Inf];
% Axes for the plot.
ax_ = axes;
set(ax_,'Units','normalized','OuterPosition',[0011]);
set(ax_,'Box','on');
axes(ax_);
hold on;
% --- Plot data that was originally in data set "Pa vs. Time"
Time = Time(:);
Pa = Pa(:);
h_ = line(Time,Pa,'Parent',ax_,'Color',[0.33333300.666667],...
'LineStyle','none', 'LineWidth',1,...
'Marker','.', 'MarkerSize',12);
xlim_(1) = min(xlim_(1),min(Time));
xlim_(2) = max(xlim_(2),max(Time));
legh_(end+1) = h_;
legt_{end+1} = 'Pa vs. Time';
% --- Create fit "fit 2"
fo_ = fitoptions('method','NonlinearLeastSquares','Lower',[2000000],'Upper',[250000201]);
ok_ = isfinite(Time) & isfinite(Pa);
if ~all( ok_ ) warning( 'GenerateMFile:IgnoringNansAndInfs',...
'Ignoring NaNs and Infs in data.' );
end
st_ = [200019.9999999999999995e-0079.9999999999999995e-008];
set(fo_,'Startpoint',st_);
ft_ = fittype('A ./ (1+x*B) .^ C',...
'dependent',{'y'},'independent',{'x'},...
'coefficients',{'A', 'B', 'C'});
% Fit this model using new data
cf_ = fit(Time(ok_),Pa(ok_),ft_,fo_);
% Alternatively uncomment the following lines to use coefficients from the % original fit. You can use this choice to plot the original fit against new % data. % cv_ = { 104931.5912352209, 19.999999878673496, 0.52056979690727823}; % cf_ = cfit(ft_,cv_{:});
% Plot this fit
h_ = plot(cf_,'fit',0.95);
set(h_(1),'Color',[100],...
'LineStyle','-', 'LineWidth',2,...
'Marker','none', 'MarkerSize',6);
% Turn off legend created by plot method. legend off;
% Store line handle and fit name for legend.
legh_(end+1) = h_(1);
legt_{end+1} = 'fit 2';
% --- Finished fitting and plotting data. Clean up. hold off;
% Display legend
leginfo_ = {'Orientation', 'vertical', 'Location', 'NorthEast'};
h_ = legend(ax_,legh_,legt_,leginfo_{:});
set(h_,'Interpreter','none');
% Remove labels from x- and y-axes. xlabel(ax_,'');
ylabel(ax_,'');
cf_
wenn ich jedoch mit einem Doppelklich, auf meine ".fig" Datei, das Programm starte, erhalte ich immer folgende Fehlermeldung und das Programm funktioniert nicht, ich muss es also immer über die ".m-fi" starten.
Fehler:
??? Undefined function or variable 'l'.
??? Attempt to reference field of non-structure array.
Error in ==> Programm>add_pushbutton1_Callback at 134
a = get(handles.input1_editText,'String');
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> Programm at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)Programm('add_pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Hallo
Das FIG-File muss ja durch M-File gestartet werden. FIG-File ist doch nur ein Container für GUI(Position, Farbe, Type...), vor dem Start muss es initialisiert werden. Das macht man mit M-FILE
TheRazorblade001
Gast
Beiträge: ---
Anmeldedatum: ---
Wohnort: ---
Version: ---
Verfasst am: 02.01.2011, 14:34
Titel:
Hallo, also ich finde es schon wichtig, dass man das Programm über einen Doppelklick auf die fig-File starten kann und nicht jedesmal die m-File vorher öffnen muss.
Das Problem bei dir liegt warscheinlich daran, dass zur Laufzeit des Programms dein lokaler Workspace nicht mit der handle-Struktur und den dazugehörigen Properties deiner fig-file gefüttert wurde. Dein handle ist immernoch ein leerer double-wert und keine Struktur.
Siehe Fehlermeldung:
a = get(handles.input1_editText,'String');
handles.input1_editText gibt es nicht in der Form.
Schreibe in deine Callback-Fkt. an den Anfang folgendes:
handle=guihandle;
Damit wird dein handle zur Laufzeit erst zu der Struktur mit den einzelnen Properties, auf die du mit get(handles.input1_editText,'String') zugreifen möchtest.
Ich hoffe ich konnte dir helfen, ich selbst hab zwei geschlagene Tage gebraucht um diesen Sch... herauszufinden.
die .m-Datei muss nicht geöffnet sein. Man kann sie auch über Rechts-Klick -> Run oder von der Kommandozeile aus öffnen.
Grüße,
Harald
Einstellungen und Berechtigungen
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.