Not enough input arguments

조회 수: 2 (최근 30일)
Emre ACAR
Emre ACAR 2021년 5월 1일
댓글: Walter Roberson 2021년 5월 1일
I have the error for line15 as foollows
Error in knifEdge (line 15)
NormalizedPower = TransmittedPower./max(TransmittedPower); % Normalizing Power
the code is as follows:
function [w, x0, fitresult, gof] = knifEdge(x, TransmittedPower)
% knifEdge(x,NormalizedPower)
% Knife edge method: Calculation of beam waist and center of the beam
%
% Input :
% X Input : Knife position (eg. in mm)
% Y Output: Power for each of the x position.
% Output:
% w = beam waist
% x0 = center of the beam
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%% Fit: ‘Error Function Fitting’.
NormalizedPower = TransmittedPower./max(TransmittedPower); % Normalizing Power
x = x-min(x);
lincoeff = polyfit(x, NormalizedPower, 1);
a = lincoeff(1);
[xData, yData] = prepareCurveData( x, NormalizedPower );
% Fit Type
if a<0
ft = fittype( '0.5*(1-erf(sqrt(2).*(x-x0)./w))', 'independent', 'x', 'dependent', 'y' );
else
ft = fittype( '0.5*(1+erf(sqrt(2).*(x-x0)./w))', 'independent', 'x', 'dependent', 'y' );
end
opts = fitoptions( Method, 'NonlinearLeastSquares' );
opts.Display = Off;
opts.StartPoint = [0.913375856139019 0.63235924622541];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( Name, 'Error Function Fitting' );
h = plot( fitresult, xData, yData );
legend( h, 'x vs Normalized Power' , 'Error Function Fitting', 'Location', 'NorthEast' );
w = fitresult.w;
x0 = fitresult.x0;
% Label axes
xlabel x
ylabel NormalizedPower
grid on
I have data from the experiment for x and power transmitted. I imported it into matlab as .mat format and defined x and transmittedpower from the table. But its not working . I dont know what i am missing.
  댓글 수: 2
Mario Malic
Mario Malic 2021년 5월 1일
TransmittedPower is a structure?
Emre ACAR
Emre ACAR 2021년 5월 1일
It should be input from my experiment data

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

답변 (1개)

Walter Roberson
Walter Roberson 2021년 5월 1일
You are trying to execute knifEdge by name or by pressing the green Run button. You need to go to the command line and invoke it passing in the appropriate values (or do the same thing in a line of code.)
When you run a function it is not enough to have variables in the workspace that have the same names as the variables used in the function; you must pass the values in to the function.
  댓글 수: 6
Emre ACAR
Emre ACAR 2021년 5월 1일
in the command window i typed this >> knifEdge(x,TransmittedPower), but here i have another error now.
Error using max
Invalid data type. First argument must be numeric or logical.
Error in knifEdge (line 15)
NormalizedPower = TransmittedPower./max(TransmittedPower); % Normalizing Power
Walter Roberson
Walter Roberson 2021년 5월 1일
You need to pass numeric TransmittedPower but you are passing a table instead. You need to extract the numeric data from the table.

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

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by