Verfasst am: 02.09.2010, 01:58
Titel: Curve Fittung und GUIs
Hallo zusammen, bin ein Neuling was Matlab betrifft
Habe die Suchfunktion benutzt, jedoch keine Lösung für mein Problem gefunden.
Ich habe ein CurveFitting mithilfe des cftools benutzt, und möchte nun mithilfe eines GUIs eine Oberfläche dafür erstellen, sodass der "Endbenutzer" nicht jedes mal sich durch die cftool durchklicken muss.
Hierzu habe ich mir mithilfe der cftoolbox eine M-File ausgeben lassen.
Code:
%CREATEFIT Create plot of data sets and fits
% X = Time: % Y = Pa: % 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';
% Nudge axis limits beyond data limits ifall(isfinite(xlim_))
xlim_ = xlim_ + [-11] * 0.01 * diff(xlim_);
set(ax_,'XLim',xlim_) else set(ax_, 'XLim',[-0.9899, 100.9999]);
end % --- 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_ = [200000.0010.0001];
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.54922344342, 19.999999454581101, 0.52056926448821694}; % 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_,'');
So, nun möchte ich jedoch, dass er die entsprechenden Werte für die Paramter A,B und C am "Display" ausgibt, Habe es mithilfe der "Set"Funktion probiert erhalte jedoch keine Ausgabe. Gibts dafür eine Besondere Funktion? Es wäre Super wenn ich alle Informationen (Werte der Paramter, R^2...) welche in der CFTOOL-Box ausgeben werde, auch im GUI ausgeben könnte.
Danke für eure Hilfe
bedingt dadurch, das die übergabe Parameter Time und Pa sind, habe ich das X und Y in diese umbenannt, erhalte jedoch weiterhin nicht den gezielten effekt bekomme keine Ausgabe, das Programm scheint jedoch laut commandfenster zu laufen.
Code:
functionvarargout = test(varargin) % TEST M-file for test.fig % TEST, by itself, creates a new TEST or raises the existing % singleton*.
%
% H = TEST returns the handle to a new TEST or the handle to % the existing singleton*.
%
% TEST('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in TEST.M with the given input arguments.
%
% TEST('Property','Value',...) creates a new TEST or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before test_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to test_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 test
% Last Modified by GUIDE v2.5 02-Sep-2010 02:06:57
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @test_OpeningFcn, ...
'gui_OutputFcn', @test_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
ifnargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
% --- Executes just before test is made visible. function test_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 test (see VARARGIN)
% Choose default command line output for test
handles.output = hObject;
% UIWAIT makes test wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. functionvarargout = test_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 Name_Callback(hObject, eventdata, handles) % hObject handle to Name (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 Name as text % str2double(get(hObject,'String')) returns contents of Name as a double
% --- Executes during object creation, after setting all properties. function Name_CreateFcn(hObject, eventdata, handles) % hObject handle to Name (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 Time_Callback(hObject, eventdata, handles) % hObject handle to Time (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 Time as text % str2double(get(hObject,'String')) returns contents of Time as a double
% --- Executes during object creation, after setting all properties. function Time_CreateFcn(hObject, eventdata, handles) % hObject handle to Time (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 Pa_Callback(hObject, eventdata, handles) % hObject handle to Pa (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 Pa as text % str2double(get(hObject,'String')) returns contents of Pa as a double
% --- Executes during object creation, after setting all properties. function Pa_CreateFcn(hObject, eventdata, handles) % hObject handle to Pa (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 pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles)
Time = xlsread('test.xlsx', 'A1:A21')
Pa = xlsread('test.xlsx', 'B1:B21') function cf_ = createFit(Time,Pa)
%CREATEFIT Create plot of data sets and fits
% X = Time: % Y = Pa: % 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';
% Nudge axis limits beyond data limits ifall(isfinite(xlim_))
xlim_ = xlim_ + [-11] * 0.01 * diff(xlim_);
set(ax_,'XLim',xlim_) else set(ax_, 'XLim',[-0.9899, 100.9999]);
end % --- 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_ = [200000.0010.0001];
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.54922344342, 19.999999454581101, 0.52056926448821694}; % 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_,'');
set(handles.text1,'String','cf_');
Das ist so wenig sinnvoll, da der String 'cf_' angezeigt werden wird.
Um die Informationen zu extrahieren, würde ich mir folgende Dateien, ausgehend vom Installationsverzeichnis, ansehen:
...\toolbox\curvefit\curvefit\@cfit\disp.m
...\toolbox\curvefit\curvefit\@cfit\private\makedisplay.m
und das übernehmen, was du brauchen kannst.
Wird zugegebenermaßen etwas Arbeit erfordern.
alles klar, werde mir die Dateien mal anschauen.
Bis jetzt erhalte ich den Plot angezeigt, ich benötige jedoch die Parameter der Funktion
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.