kenne mich leider nicht so gut mit Matlab aus. Sorry, wenn die Frage etwas blöd ist:
Ich habe mit cftool eine eigene Ausgleichsfunktion f(x) = a*(sin(x - pi/2)) + c erstellt, die auch super aussieht.
Ich möchte diese Ausgleichsfunktion jetzt gerne auf alle meine Messwerte loslassen, aber ich verstehe nicht, wie ich dadran komme.(Also a und c für jede Messzeile)
also an die Funktion zu kommen ist kein Problem, aber ich brauche halt die Koeffizienten. Ich habe die Funktion einfach mal "sinus" genannt und dachte mit [a,b]=sinus(x,y); bekäm ich a und c raus, aber das geht leider nicht.
Grüße
Genauso wie man ein "cfit" Objekt erstellen kann, kann man das auch mittels "save session" aus dem GUI heraus speichern.
Die Hilfe zu "cfit" hat auch ein Beispiel wie man das "cfit" Object auf Daten anwenden kann.
Code:
f = fittype('a*x^2+b*exp(n*x)')
f =
General model:
f(a,b,n,x) = a*x^2+b*exp(n*x)
c = cfit(f,1,10.3,-1e2)
c =
General model:
c(x) = a*x^2+b*exp(n*x)
Coefficients:
a = 1
b = 10.3
n = -100
Wenn ich das richtig seh oder versteh, gibst du die Koeffizieten ja selbst ein, oder?
Ich möchte diese ja berechnet haben, wie er es beim cftool auch macht.
Ein Konkretes Beispiel:
Code:
function sinus(x,y) % Data from data set "y vs. x": % X = x: % Y = y: % Unweighted
% Auto-generated by MATLAB on 24-Nov-2011 09:43:05
% Set up figure to receive data sets and fits
f_ = clf;
figure(f_);
set(f_,'Units','Pixels','Position',[654271680481]);
% 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 "y vs. x"
x = x(:);
y = y(:);
h_ = line(x,y,'Parent',ax_,'Color',[0.33333300.666667],...
'LineStyle','none', 'LineWidth',1,...
'Marker','.', 'MarkerSize',12);
xlim_(1) = min(xlim_(1),min(x));
xlim_(2) = max(xlim_(2),max(x));
legh_(end+1) = h_;
legt_{end+1} = 'Schub auf Beta';
% --- Create fit "fit 1"
ok_ = isfinite(x) & isfinite(y);
if ~all( ok_ ) warning( 'GenerateMFile:IgnoringNansAndInfs',...
'Ignoring NaNs and Infs in data.' );
end
ft_ = fittype({'(sin(x - pi/2))', '1'},...
'dependent',{'y'},'independent',{'x'},...
'coefficients',{'a', 'c'});
% Fit this model using new data
cf_ = fit(x(ok_),y(ok_),ft_);
% 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_ = { 7.232888513276353, 50.795238140574959}; % 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 1';
% --- 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('Beta') ylabel('Schub')
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.