Error using cfit/subsref when trying to fit a smoothingspline

조회 수: 4 (최근 30일)
Zhangxi Feng
Zhangxi Feng 2018년 9월 20일
편집: Walter Roberson 2025년 2월 13일
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
Walter Roberson
Walter Roberson 2025년 2월 13일
편집: Walter Roberson 2025년 2월 13일
Which MATLAB release are you using?
R2015aSP1 is the oldest MATLAB version I have easy access to. The gof output is defined by R2015aSP1.

댓글을 달려면 로그인하십시오.

답변 (1개)

Riya
Riya 2025년 2월 13일
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!

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by