Error using cfit/subsref when trying to fit a smoothingspline
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
According to documentation, if a fittype is specified, the output becomes [curve,gof] = fit(x,y,fttype)
My code is shown as follows:
A = importdata('exp65_C1.SS');
[x,y] = prepareCurveData(A(:,1),A(:,2));
[fit_o,~] = fit(x,y,'smoothingspline');
I get the error:
Error using cfit/subsref
Too many output arguments.
When I execute the fit line. I checked that x and y are both single column vectors of size 12776x1, and both have the same dimensions. The data goes from 0 to 0.83 for x, and 0 to 726 for y.
When I remove the ~ since it said I have too many output arguments, it gives this error instead:
Error using cfit/subsref>iParenthesesReference (line 36)
Too many inputs to CFIT/SUBSREF.
Error in cfit/subsref (line 15)
out = iParenthesesReference( obj, currsubs );
Which makes sense since fttype requires more than one output. Same error if I don't specify an output at all.
What is going on?
1 Kommentar
Walter Roberson
am 13 Feb. 2025
Bearbeitet: Walter Roberson
am 13 Feb. 2025
Which MATLAB release are you using?
R2015aSP1 is the oldest MATLAB version I have easy access to. The gof output is defined by R2015aSP1.
Antworten (1)
Riya
am 13 Feb. 2025
Hi Zhangxi,
I understand that you are encountering an error while trying to fit a "smoothingspline" to your dataset. I tried reproducing the issue with the following sample code:
clc; clear; close all;
% Generate synthetic data similar to yours
x = linspace(0, 0.83, 12776)'; % Column vector
y = linspace(0, 726, 12776)'.^1.5 + randn(12776,1)*10;
% Prepare curve data
[xData, yData] = prepareCurveData(x, y);
% Attempt to fit with smoothingspline
[fit_o, gof] = fit(xData, yData, 'smoothingspline');
% Display outputs
disp('Fitted Model:');
disp(fit_o);
disp('Goodness of Fit:');
disp(gof);
% Plot results
figure;
plot(fit_o, xData, yData);
title('Smoothing Spline Fit');
xlabel('x');
ylabel('y');
grid on;
This code is running successfully without any errors. It might be the case that there is some issue related to the dataset file “exp65_C1.SS” that you are using. You can try the following commands to make sure it contains numeric data and has the expected dimensions.
A = importdata('exp65_C1.SS');
size(A)
whos A
You can also try running the provided sample code to verify that the functions are working fine. If the problem still exists, please share the “exp65_C1.SS” file that you are using so that I can further debug the issue.
For more information about fitting a smoothing spline curve, please refer the following documentation:
Thanks!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!