problem with Fit function

조회 수: 6 (최근 30일)
Gustaw Rutkowski
Gustaw Rutkowski 2020년 11월 11일
편집: Abhaya 2025년 1월 21일
Hello, I have strange problem cause, on my computer fit function just desn't work. I thought that's my fault but code that I write compile properly in matlab online but does not in custom version, what's more I installed the curve fitting tool and ask for generating code matalb can;t run that program which was generated by it. Here is code, i would be gratful for pasting it into your matalb and say do you also get an error. My error is:
Error in createFit2 (line 18)
[xData, yData] = prepareCurveData( x, y );
Code generted by matlab:
function [fitresult, gof] = createFit2(x, y)
%CREATEFIT2(X,Y)
% Create a fit.
%
% Data for 'Dioda 1' fit:
% X Input : x
% Y Output: y
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 11-Nov-2020 23:05:36
%% Fit: 'Dioda 1'.
[xData, yData] = prepareCurveData( x, y );
% Set up fittype and options.
ft = fittype( 'exp1' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Normalize = 'on';
opts.StartPoint = [117.535994401642 3.22582417353711];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'Dioda 1' );
plot( fitresult, xData, yData );
% Label axes
xlabel( 'x', 'Interpreter', 'none' );
ylabel( 'y', 'Interpreter', 'none' );
grid on

답변 (1개)

Abhaya
Abhaya 2025년 1월 21일
편집: Abhaya 2025년 1월 21일
The error 'Error in createFit2 (line 18) [xData, yData] = prepareCurveData( x, y );' indicates that MATLAB could not find appropriate prepareCurveData function while excuting 'createFit2' function. While I did not encounter any error when running the code, you can try the following steps to resolve the issue:
  • MATLAB Path Issues:Sometimes, MATLAB might not be able to access certain functions if they are not in the correct directory or if the toolbox is not added to the MATLAB path. You can try resetting the MATLAB path, which might help resolve any path-related issues.
restoredefaultpath;
rehash toolboxcache;
  • Input Data Format: Make sure that x and y are vectors of the same length, and that they are properly defined before calling the createFit2 function.
  • Conflicting Function or Variable Names: Ensure that there are no conflicting variable names in your workspace that could be overshadowing the prepareCurveData function. You can clear the workspace before running the createFit2 function.
clear all;
For more information, please go through the MATLAB documentation for 'prepareCurveData' function.

카테고리

Help CenterFile Exchange에서 Fit Postprocessing에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by