Not Enough Input Arguments

3.165 visualizzazioni (ultimi 30 giorni)
TheLimpNinja
TheLimpNinja il 7 Nov 2012
Hi, I'm very new to MATLAB and I am having some trouble. Lots of people have had the same problem but nobody seems to be able to explain or solve it in plain English. Could somebody please explain what this error is and how to fix it?
I have a simple function:
function [r]=Mec134function(w,theta_deg)
t2=10000;
theta_rad=(theta_deg./180).*pi;
t1=55090./(10*sin(theta_rad));
rx=(t1.*cos(theta_rad))-t2;
ry=w-(t1.*sin(theta_rad));
r=((rx).^2+(ry).^2).^0.5;
end
It seems to give this error for line 3 but I'm not sure why.
Thanks.
  13 Commenti
Steven Lord
Steven Lord il 9 Mar 2022
Based on the signature I'm guessing you're writing this for use as the first input in a call to one of the ODE solvers. If that's correct I'm guessing your ODE solver call probably looks something like:
[t, y] = ode45(TLD_SDOF, ...)
That will attempt to call TLD_SDOF with 0 input arguments and pass the function handle that call returns into ode45 as its first input. But your TLD_SDOF function uses both its inputs and so it must be called with 2 input arguments.
The solution is to not call TLD_SDOF yourself but to pass a function handle to it into the ODE solver. The ODE solver can then use that function handle to call your function and the ODE solver will pass the two required inputs into TLD_SDOF when it does.
[t, y] = ode45(@TLD_SDOF, ...)
As a side note, instead of sharing data with your ODE function using global variables I strongly recommend you use one of the techniques described on this documentation page instead. Trying to debug an issue related to why a global variable doesn't have the value you expect is almost always very difficult and time consuming.
Walter Roberson
Walter Roberson il 9 Mar 2022
If there had been a wrapper script calling ode45 then the traceback should have shown another line showing the place TLD_SDOF was called.
So either the user chopped the error message (certainly a possibility), or else the user invoked TLD_SDOF directly without any wrapper script, probably by pressing the green Run button (which is something thath appens a lot of the time.)

Accedi per commentare.

Risposta accettata

Akiva Gordon
Akiva Gordon il 8 Nov 2012
Modificato: MathWorks Support Team il 27 Nov 2018
Your function defines 2 input arguments (w and theta_deg). When you run Mec134function, you must specify exactly two inputs, otherwise you will get the error "Not enough input arguments".
For example, if you run the Mec134function in the command window without specifying any arguments:
>> Mec134function
You get this error:
Not enough input arguments.
Error in Mec134function (line 3)
theta_rad=(theta_deg./180).*pi;
If you run the Mec134function and specify two input arguments, "w" and "theta_deg" (assuming "w" and "theta_deg" are defined), you do not get the error message:
>> Mec134function(w,theta_deg)
If you have the file "Mec134function.m" open in the Editor and you try to run the function by pressing the "Run" button or F5, MATLAB runs the Mec134function without any input arguments, and you get the error "Not enough input arguments". The "Run" button dropdown menu then opens prompting you to enter values for the missing input arguments.
Add the desired values and press enter. The values you enter are set as the default inputs when you click the "Run" button or F5 in the future.
To change the values, press the down arrow below the "Run" button and enter new values.
  7 Commenti
Achintya Sujan
Achintya Sujan il 30 Giu 2022
Thank you Akiva, your comment below helped me clear the "Not enough input arguments" error in my MATLAB program.
"If you have the file "Mec134function.m" open in the Editor and you try to run the function by pressing the "Run" button or F5, MATLAB runs the Mec134function without any input arguments, and you get the error "Not enough input arguments".
Cedric Kouokam Kamdem
Cedric Kouokam Kamdem il 1 Lug 2022
thanks Akiva you coment was very helpfull for me

Accedi per commentare.

Più risposte (19)

TheLimpNinja
TheLimpNinja il 7 Nov 2012
Modificato: Walter Roberson il 15 Lug 2016
sorry the function is
function [r]=Mec134function(w,theta_deg)
t2=10000;
theta_rad=(theta_deg./180).*pi;
t1=55090./(10*sin(theta_rad));
rx=(t1.*cos(theta_rad))-t2;
ry=w-(t1.*sin(theta_rad));
r=((rx).^2+(ry).^2).^0.5;
end
if that's clearer :-)
  3 Commenti
David Barry
David Barry il 7 Nov 2012
Jonathan is correct, please ignore the other answer below.
As a complete aside, MATLAB has commands deg2rad and rad2deg.
Steven Lord
Steven Lord il 27 Dic 2016
Prior to release R2015b the deg2rad and rad2deg functions were part of Mapping Toolbox. In that release they moved into MATLAB.
As another solution that avoids converting between degrees and radians, MATLAB also has functions sind and cosd for computing the sine and cosine of angles in degrees and those have been part of MATLAB for quite some time. [I don't remember exactly when they were introduced.]

Accedi per commentare.


TheLimpNinja
TheLimpNinja il 7 Nov 2012
Modificato: Walter Roberson il 7 Nov 2012
Thanks :-)
will have a look at the "getting started"
I have a simple function:
function [r]=Mec134function(w,theta_deg)
t2=10000;
theta_rad=(theta_deg./180).*pi;
t1=55090./(10*sin(theta_rad));
rx=(t1.*cos(theta_rad))-t2;
ry=w-(t1.*sin(theta_rad));
r=((rx).^2+(ry).^2).^0.5;
end
that seems to give this error for line 2 but I'm not sure why.
  2 Commenti
Jan
Jan il 30 Nov 2012
Modificato: Jan il 30 Nov 2012
@TheLimpNinja: Please add all details, which describe the problem in the questions - you can edit it. The answers section is reserved for answers.
Waldemiro Kubucama
Waldemiro Kubucama il 1 Ago 2020
Hello, first press button "Run" in Matlab and after only you press the button "ENTER" i your computer. I think your problem will be solved.

Accedi per commentare.


Brian Batson
Brian Batson il 29 Nov 2012
Modificato: Brian Batson il 29 Nov 2012
I too am very new to Matlab, and tried to run the code above in .m (JP Donlon on Nov. 7th). However, I keep getting an error stating "Not enough input arguments." I'm not sure what this means, because I have attempted to run other code by professors which works on other computers. Is it something with my preference settings?
Also, when I run the Code Analyzer, there are no issues...not sure what is going on.
  4 Commenti
Prerna Singh
Prerna Singh il 29 Mar 2020
Hi,
Could you please explain what do you mean by passing the arguments?
Thanks
prerna
Walter Roberson
Walter Roberson il 29 Mar 2020
https://www.mathworks.com/matlabcentral/answers/53100-not-enough-input-arguments#comment_109973

Accedi per commentare.


Annie micheal
Annie micheal il 15 Lug 2016
Modificato: Walter Roberson il 15 Lug 2016
How to rectify this error
Error using DetectFace (line 68)
Not enough input arguments.
the code is given below
I=imread('lena.jpg');
minFace = 20; % minimal size of the face that you are searching for
maxFace = 4000; % maximal size of the face that you are searching for
overlappingThreshold = 0.5; % overlapping threshold for grouping nearby detections
numThreads = 24; % number of cpu threads for parallel computing
if nargin > 2 && ~isempty(options)
if isfield(options, 'minFace') && ~isempty(options.minFace)
minFace = options.minFace;
end
if isfield(options, 'maxFace') && ~isempty(options.maxFace)
maxFace = options.maxFace;
end
if isfield(options, 'overlappingThreshold') && ~isempty(options.overlappingThreshold)
overlappingThreshold = options.overlappingThreshold;
end
if isfield(options, 'numThreads') && ~isempty(options.numThreads)
numThreads = options.numThreads;
end
end
%%test detector
if ~ismatrix(I)
I = rgb2gray(I);
end
candi_rects = NPDScan(model, I, minFace, maxFace, numThreads);
%%post processing
if isempty(candi_rects)
rects = [];
return;
end
  3 Commenti
Annie micheal
Annie micheal il 15 Lug 2016
Modificato: Walter Roberson il 15 Lug 2016
yeah i got it from NPDFaceDetector...
the entire code is
I=imread('lena.jpg');
minFace = 20; % minimal size of the face that you are searching for
maxFace = 4000; % maximal size of the face that you are searching for
overlappingThreshold = 0.5; % overlapping threshold for grouping nearby detections
numThreads = 24; % number of cpu threads for parallel computing
if nargin > 2 && ~isempty(options)
if isfield(options, 'minFace') && ~isempty(options.minFace)
minFace = options.minFace;
end
if isfield(options, 'maxFace') && ~isempty(options.maxFace)
maxFace = options.maxFace;
end
if isfield(options, 'overlappingThreshold') && ~isempty(options.overlappingThreshold)
overlappingThreshold = options.overlappingThreshold;
end
if isfield(options, 'numThreads') && ~isempty(options.numThreads)
numThreads = options.numThreads;
end
end
%%test detector
if ~ismatrix(I)
I = rgb2gray(I);
end
candi_rects = NPDScan(model, I, minFace, maxFace, numThreads);
%%post processing
if isempty(candi_rects)
rects = [];
return;
end
numCandidates = length(candi_rects);
predicate = eye(numCandidates); % i and j belong to the same group if predicate(i,j) = 1
% mark nearby detections
for i = 1 : numCandidates
for j = i + 1 : numCandidates
h = min(candi_rects(i).row + candi_rects(i).size, candi_rects(j).row + candi_rects(j).size) - max(candi_rects(i).row, candi_rects(j).row);
w = min(candi_rects(i).col + candi_rects(i).size, candi_rects(j).col + candi_rects(j).size) - max(candi_rects(i).col, candi_rects(j).col);
s = max(h,0) * max(w,0);
if s / (candi_rects(i).size^2 + candi_rects(j).size^2 - s) >= overlappingThreshold
predicate(i,j) = 1;
predicate(j,i) = 1;
end
end
end
% merge nearby detections
[label, numCandidates] = Partition(predicate);
rects = struct('row', zeros(numCandidates,1), 'col', zeros(numCandidates,1), ...
'size', zeros(numCandidates,1), 'score', zeros(numCandidates,1), ...
'neighbors', zeros(numCandidates,1));
for i = 1 : numCandidates
index = find(label == i);
weight = Logistic([candi_rects(index).score]');
rects(i).score = sum( weight );
rects(i).neighbors = length(index);
if sum(weight) == 0
weight = ones(length(weight), 1) / length(weight);
else
weight = weight / sum(weight);
end
rects(i).size = floor([candi_rects(index).size] * weight);
rects(i).col = floor(([candi_rects(index).col] + [candi_rects(index).size]/2) * weight - rects(i).size/2);
rects(i).row = floor(([candi_rects(index).row] + [candi_rects(index).size]/2) * weight - rects(i).size/2);
end
clear candi_rects;
% find embeded rectangles
predicate = false(numCandidates); % rect j contains rect i if predicate(i,j) = 1
for i = 1 : numCandidates
for j = i + 1 : numCandidates
h = min(rects(i).row + rects(i).size, rects(j).row + rects(j).size) - max(rects(i).row, rects(j).row);
w = min(rects(i).col + rects(i).size, rects(j).col + rects(j).size) - max(rects(i).col, rects(j).col);
s = max(h,0) * max(w,0);
if s / rects(i).size^2 >= overlappingThreshold || s / rects(j).size^2 >= overlappingThreshold
predicate(i,j) = true;
predicate(j,i) = true;
end
end
end
flag = true(numCandidates,1);
% merge embeded rectangles
for i = 1 : numCandidates
index = find(predicate(:,i));
if isempty(index)
continue;
end
s = max([rects(index).score]);
if s > rects(i).score
flag(i) = false;
end
end
rects = rects(flag);
% check borders
[height, width, ~] = size(I);
numFaces = length(rects);
for i = 1 : numFaces
if rects(i).row < 1
rects(i).row = 1;
end
if rects(i).col < 1
rects(i).col = 1;
end
rects(i).height = rects(i).size;
rects(i).width = rects(i).size;
if rects(i).row + rects(i).height - 1 > height
rects(i).height = height - rects(i).row + 1;
end
if rects(i).col + rects(i).width - 1 > width
rects(i).width = width - rects(i).col + 1;
end
end
end
function Y = Logistic(X)
Y = log(1 + exp(X));
Y(isinf(Y)) = X(isinf(Y));
end
Walter Roberson
Walter Roberson il 15 Lug 2016
Why did you use nargin and return when you wrote this script ? nargin is defined as being 0 within scripts and return can lead to odd behavior when used within a script .
When I search around, it looks to me as if this code is ripped off from https://github.com/biotrump/NPD/blob/master/NPDFaceDetector/DetectFace.m which is a function not a script . An example of calling that function is given in the comments there:
I = imread('lena.jpg');
load('model.mat');
rects = DetectFace(npdModel, I);
You cannot just remove the function line from a function and assign to one variable and expect it to work.

Accedi per commentare.


REEMA MOHANTY
REEMA MOHANTY il 27 Dic 2016
Modificato: Walter Roberson il 26 Mag 2017
clc; clear; close all;
xo=0.4;
A=[];
b=[];
Aeq=[];
beq=[];
Q=100;
R=1;
N = 50;
U0= zeros(100,1);
% Umin= -1*ones(100,1);
% Umax=1*ones(100,1);
% U = fmincon(@cost1,U0,A,b,Aeq,beq,Umin,Umax,[],[],N);
x=xo; h = 0.1;
xo=[-0.5,0.5];
options = optimoptions(@fmincon,'Algorithm','sqp');
U = fmincon(@cost1,U0,[],[],[],[],[],[],@confuneq,options);
for k =1:N
S1= F(x(k),U(k));
S2=F(x(k)+0.5*h*S1,U(k));
S3=F(x(k)+0.5*h*S2,U(k));
S4=F(x(k)+h*S3,U(k));
x(k+1) = x(k) + (1/6)* (S1+ 2*S2+ 2*S3 + S4)*h;
k = k + 1 ;
end
% plot(x);
plot(U);
grid on
figure(); plot(x)
grid on
I new to matlab.Can anyone help me to fix the iisue here.
Its showing not enough input arguments.

vani shree
vani shree il 3 Mar 2017
Modificato: Walter Roberson il 3 Mar 2017
Hello sir,I am newer to matlab. I am getting error in this code like "preprocessing requries more input arugument to run". can you please to run this program. my project topic is recognition and matching fake logos using filters.
function img=preprocessing(I)
[x y o]=size(I);
if o==3
I=rgb2gray(I);
end
I=im2double(I);
%%MEDIAN FILTER
med=medfilt2(I);
figure,imshow(med)
title('MEDIAN FILTERED IMAGE')
[psnr_med,mse_med]=psnr(I,med)
%%AVERAGE FILTER
out7= imfilter(I, fspecial('average'));
figure,imshow(out7)
title('MEAN FILTERED IMAGE')
[psnr_avg,mse_avg]=psnr(I,out7)
%%GAUSSIAN FILTER
gau=imfilter(I,fspecial('gaussian'));
figure,imshow(gau)
title('GAUSSIAN FILTER IMAGE')
[psnr_gau,mse_avg]=psnr(I,gau)
%%WEINER FILTER
psf=fspecial('gaussian',7,10);
image1=imfilter(I,psf,'conv','circular');
var1=(1/256)^2/12;
var2=var(I(:));
wei=deconvwnr(image1,psf,(var1/var2));
figure,imshow(wei);title('WEINER FILTERED IMAGE');
[psnr_wei,mse_wei]=psnr(I,wei)
psnr_all=[psnr_med,psnr_avg,psnr_gau,psnr_wei];
psnr_max=max(psnr_all);
val=find(psnr_all==psnr_max);
if val==1
img=med;
disp('median have high psnr');
elseif val==2
img=out7;
disp('mean have high psnr');
elseif val==3
img=gau;
disp('gaussian have high psnr');
else
img=wei;
disp('weiner have high psnr');
end
  3 Commenti
vani shree
vani shree il 24 Mar 2017
thank you very much sir. and i have some other doubts regarding my project.my project title is recognition and detection of lake logos by context. i done 60% of coding like preprocessing and SIFT process but i dont know how to compare fake logo and original logo and the output should display which is fake logo. can u please help me to compare these two images.
Steven Lord
Steven Lord il 24 Mar 2017
vani shree, you should ask this as a separate question since it's not related to the "not enough input arguments" original question. Show what you've written and ask a specific question about where you're having difficulty and you may receive some guidance.

Accedi per commentare.


Ganesh Petkar
Ganesh Petkar il 18 Apr 2017
I am getting error for below function as "Not enough input arguments. "
delayed_signal = mtapped_delay_fcn(input);

Wendell
Wendell il 26 Mag 2017
Modificato: Walter Roberson il 26 Mag 2017
Hi I'm trying to run Dr. John Stockie's matlab code but I am getting a "Not enough input argument" error. I'm not very well verse with Matlab, so I would appreciate any help...Thank you. I am pasting the code:
function C = ermak( x, y, z, H, Q, U, Wset, Wdep )
% ERMAK: Compute contaminant concentration (kg/m^3) using the
% Gaussian plume model, modified for a deposition and settling
% velocity. This code handles a single source (located at the
% origin) and multiple receptors.
%
% Input parameters:
%
% x - receptor locations: distance along the wind direction, with
% the source at x=0 (m)
% y - receptor locations: cross-wind direction (m)
% z - receptor locations: vertical height (m)
% H - source height (m)
% Q - contaminant emission rate (kg/s)
% U - wind velocity (m/s)
% Wset - gravitational settling velocity (m/s)
% Wdep - deposition velocity (m/s)
%
% Output:
%
% C - contaminant concentration (kg/m^3)
%
% References: Ermak (1977), Winges (1990/1992).
% First, define the cut-off velocity, below which concentration = 0.
Umin = 0.0;
% Determine the sigma coefficients based on stability class C --
% slightly unstable (3-5 m/s).
ay = 0.34; by = 0.82; az = 0.275; bz = 0.82;
sigmay = ay*abs(x).^by .* (x > 0);
sigmaz = az*abs(x).^bz .* (x > 0);
% Calculate the eddy diffusivity (m^2/s).
Kz = 0.5*az*bz*U*abs(x).^(bz-1) .* (x > 0); % K = 0.5*U*d(sigma^2)/dx
% Calculate the contaminant concentration (kg/m^3) using Ermak's formula.
if U < Umin,
C = 0 * z;
else
Wo = Wdep - 0.5*Wset;
C = Q ./ (2*pi*U*sigmay.*sigmaz) .* exp( -0.5*y.^2./sigmay.^2 ) .* ...
exp( -0.5*Wset*(z-H)./Kz - Wset^2*sigmaz.^2/8./Kz.^2 ) .* ...
( exp( -0.5*(z-H).^2./sigmaz.^2 ) + ...
exp( -0.5*(z+H).^2./sigmaz.^2 ) - sqrt(2*pi)*Wo*sigmaz./Kz .* ...
exp( Wo*(z+H)./Kz + 0.5*Wo^2*sigmaz.^2./Kz.^2 ) .* ...
erfc( Wo*sigmaz/sqrt(2)./Kz + (z+H)./sqrt(2)./sigmaz ) );
ii = find(isnan(C) | isinf(C));
C(ii) = 0; % Set all NaN and inf values to zero.
end
and the error message refers to "sigmay" in line 31

aarthy reddy R
aarthy reddy R il 4 Set 2019
Modificato: Walter Roberson il 14 Ott 2019
function test(num1, num2,small,s)
load (small, num1, num2)
s = sum(num1, num2)
end
this the code for this i'm getting these errors
Not enough input arguments.
Error in test (line 3)
load (small, num1, num2)
  4 Commenti
Walter Roberson
Walter Roberson il 14 Ott 2019
Okay, well you are trying to run test without passing in at least 3 input arguments. For example you might be trying to just press the green Run button, instead of going down to the command line and issuing a command in the command window.
Walter Roberson
Walter Roberson il 14 Ott 2019
Note: if you pass in the name of a variable as the fourth parameter, then the function you posted will not set that variable to the result of the sum. If you want to return a value in MATLAB you need to code it on the left side of an "=" in the function line. For example,
function s = test(num1, num2, small)
load (small, num1, num2)
s = sum(num1, num2)
end
This is unlikely to work the way you want it. In order for the load() to work there, small and num1 and num2 would each have to be a character vector or else a scalar string variable, and num1 and num2 would have to be in the same form as valid MATLAB variable names. Those names would have to be found inside the .mat file named by the small variable.
With the form of load() you have used, MATLAB would normally "poof" the variable names into existence. However, when you use end matching a function statement, you make a promise to MATLAB that you will not poof variables into existence, and MATLAB is permitted to give an error or to ignore the magically created variables. Therefore after the load, num1 and num2 are probably going to continue to be the character vectors or string objects, and you would attempt to call sum() passing those in. sum() would give an error if the first parameter, num1 is a string object, but would be okay with num1 being a character vector. There are a limited number of character vectors or scalar string objects that are valid for the second parameter of sum(), namely 'all', 'double', 'native', 'default', 'includenan', or 'omitnan' . It would be surprising if you happened to name your variables any of those...

Accedi per commentare.


Chapat
Chapat il 11 Mar 2020
Modificato: Walter Roberson il 11 Mar 2020
Hello. Am new in Matlab and I want to do my assignment with this function refraction_2layers and Matlab is saying error using refraction_2layers (line 18 and 25) Here is the whole program
function refraction_2layers(v1, v2, z, FIRST_ARRIVALS_ONLY);
% refraction_2layers(v1, v2, z);
%
% Creates travel time plots for a two-layers system with layer velocities
% v1 and v2 and layer 1 thickness of z
% The FIRST_ARRIVALS_ONLY FLAG may be set to 1 to plot only the first arrivals. By
% default, all arrivals are plotted.
if nargin < 4 FIRST_ARRIVALS_ONLY = 0; end
%% X-positions for geophones (m, relative to source)
x = [0:5:300];
%% Direct wave %% Travels along ground surface (at velocity v1)
t1 = x./v1;
%% Head wave
%% Refracts along z1-z2 boundary
%% Travel time depends on velocities of both layers
%% and thickness of layer 1 only (thickness of layer 2 irrelevant)
t2 = (2*z*sqrt(v2^2-v1^2)/(v1*v2))+x./v2; %% Note slope should be 1/v2!
xcrit = 2*z*v1/(sqrt(v2^2-v1^2));
if isreal(xcrit)
a = min(find(x>xcrit));
end
crossover = ((2*z*sqrt(v2^2-v1^2))/(v1*v2))/(1/v1-1/v2);
b = max(find(x<= crossover));
if FIRST_ARRIVALS_ONLY
plot(x(1:b),t1(1:b)*1000, '.--')
hold on
if isreal(t2)
plot(x(b:end), t2(b:end)*1000, 'r.--')
end
else
plot(x,t1*1000, '.--')
hold on
if isreal(t2)
plot(x(a:end), t2(a:end)*1000, 'r.--')
end
end
xlabel('GEOPHONE OFFSET (m)')
ylabel('TIME (ms)')
grid on
legend('DIRECT WAVE', 'HEAD WAVE')
title(['z1 = ', num2str(z), ' m; v1 = ', num2str(v1), ' m/s; v2 = ', num2str(v2), ' m/s'])
axis ([0 300 0 300])
hold off
  1 Commento
Walter Roberson
Walter Roberson il 11 Mar 2020
I formatted your code for you to make it readable to other people, but I suspect that I did not exactly preserve the line boundaries, so we do not know which lines are giving you the problem. Please mark them by using comments. Please also give the exact error messages.
Also please check the position of the end statements. It looked to me as if you might have had two extra end statements.

Accedi per commentare.


Josilyn Dostal
Josilyn Dostal il 23 Apr 2020
I am really struggling to figure out this "not enough input arguments" error in my code. Any help would be greatly appreciated! This is for a batch distillation problem, and the error is referring to the temp function near the bottom. The code and error are below:
P = 912; % mmHg or 1.2 atm
L0 = 100; % Moles liquid in the still initially
A = [6.90565 6.95464]; B=[1211.033 1344.8]; C=[220.79 219.482]; % Antoine Constants
% x0 = [0.60 0.40]; % Initial liquid concentration xb = 60% xt = 40%
% xf = [0.20 0.80]; % Final liquid concentration xb = 20% xt = 80%
xtspan = linspace(0.40,0.80,100);
[xt, L] = ode45(@Moles, xtspan, L0);
L = L(end);
fprintf('The amount of liquid remaining in the still when liquid mole fraction of toluene reaches 0.80 is %f moles', L);
% Vapor liquid equilibrium ratio, K
function Kt = EquilibriumRatio(Psatt)
Kt = Psatt/P;
end
% Toluene vapor pressure
function Psatt = VaporPressuret(T,A,B,C)
Psatt = 10^(A(2)-B(2)/(T+C(2)));
end
% Benzene vapor pressure
function Psatb = VaporPressureb(T,A,B,C)
Psatb = 10^(A(1)-B(1)/(T+C(1)));
end
% ODE
function dLdx = Moles(xt,L)
T0 = 95.585;
%options = odeset('RelTol',1e-6,'AbsTol',1e-8);
%options = optimset('PlotFcns',{@optimplotx,@optimplotfval});
%options = optimset('Display','iter'); % show iterations
options = optimset('Display','off','TolX',1e-6); % Options
T = fzero(@temp, T0, options);
Psatt = VaporPressuret(T);
Kt = EquilibriumRatio(Psatt);
dLdx = L/(xt*(Kt-1));
end
function Tempfun = temp(T,xt,P,A,B,C)
Psatt = VaporPressuret(T,A,B,C);
Psatb = VaporPressureb(T,A,B,C);
Tempfun = Psatt*xt + Psatb*(1-xt) - P;
end
>> project2
Error using fzero (line 306)
FZERO cannot continue because user-supplied function_handle ==> temp failed with the error below.
Not enough input arguments.
Error in project2>Moles (line 30)
T = fzero(@temp, T0, options);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in project2 (line 7)
[xt, L] = ode45(@Moles, xtspan, L0);
  5 Commenti
Walter Roberson
Walter Roberson il 24 Apr 2020
P = 912; % mmHg or 1.2 atm
L0 = 100; % Moles liquid in the still initially
A = [6.90565 6.95464]; B=[1211.033 1344.8]; C=[220.79 219.482]; % Antoine Constants
% x0 = [0.60 0.40]; % Initial liquid concentration xb = 60% xt = 40%
% xf = [0.20 0.80]; % Final liquid concentration xb = 20% xt = 80%
xtspan = linspace(0.40,0.80,100);
[xt, L] = ode45(@(xt,L) Moles(xt,L,P,A,B,C), xtspan, L0);
L = L(end);
fprintf('The amount of liquid remaining in the still when liquid mole fraction of toluene reaches 0.80 is %f moles', L);
% ODE
function dLdx = Moles(xt, L, P, A, B, C)
T0 = 95.585;
%options = odeset('RelTol',1e-6,'AbsTol',1e-8);
%options = optimset('PlotFcns',{@optimplotx,@optimplotfval});
%options = optimset('Display','iter'); % show iterations
options = optimset('Display','off','TolX',1e-6); % Options
T = fzero(@(T)temp(T,xt,P,A,B,C), T0, options);
Psatt = VaporPressuret(T, A, B, C);
Kt = EquilibriumRatio(Psatt, P);
dLdx = L/(xt*(Kt-1));
end
function Tempfun = temp(T, xt, P, A, B, C)
Psatt = VaporPressuret(T, A, B, C);
Psatb = VaporPressureb(T, A, B, C);
Tempfun = Psatt*xt + Psatb*(1-xt) - P;
end
% Toluene vapor pressure
function Psatt = VaporPressuret(T, A, B, C)
Psatt = 10^(A(2)-B(2)/(T+C(2)));
end
% Vapor liquid equilibrium ratio, K
function Kt = EquilibriumRatio(Psatt, P)
Kt = Psatt/P;
end
% Benzene vapor pressure
function Psatb = VaporPressureb(T, A, B, C)
Psatb = 10^(A(1)-B(1)/(T+C(1)));
end
Josilyn Dostal
Josilyn Dostal il 24 Apr 2020
You are my savior. Youre so nice.

Accedi per commentare.


Gurwinder pal singh Bhinder
hi
I am new to matlab. i am getting error message "extract_features" requires more input arguments to run.
anderror in command window :
>> Extract_Features
Not enough input arguments.
Error in Extract_Features (line 2)
img1 = imread(filename);
code is written below:
function Extract_Features(filename,flag)
img1 = imread(filename);
if ndims(img1) == 3; img1 = rgb2gray(img1); end % Color Images
disp(['Extracting features from ' filename ' ...']);
fir=ext_finger(img1,0);
fir=fir(fir(:,3)<5,:);
if flag ==1
figure;
imshow(img1);
hold on
fir1=find(fir(:,3)==1);
fir3=find(fir(:,3)==3);
plot(fir(fir1,1),fir(fir1,2),'r+');
plot(fir(fir3,1),fir(fir3,2),'bo');
end
filename2=filename; filename2(end-1)='x'; filename2(end)='t';
save(filename2,'fir','-ascii');
end
  8 Commenti
Gurwinder pal singh Bhinder
thank you for your help
Walter Roberson
Walter Roberson il 27 Nov 2020
Right.

Accedi per commentare.


Muhammad Hadyan Utoro
Muhammad Hadyan Utoro il 17 Giu 2021
Can someone help me please
%% Full-wave Rectification and RMS Envelope
rec_EMG = abs(EMG);
envelope = zeros(L,1);
window = 50;
envelope = sqrt(movmean(rec_EMG.^2), 'window');
I was trying to do get the RMS but it says:
Error using movmean Not enough input arguments.
I didn't understand that, as I already use two arguments there.
Thanks fo ryour help
  2 Commenti
Walter Roberson
Walter Roberson il 17 Giu 2021
In order to use movmean(), you have to pass in the signal whose moving mean is to be taken, and you have to pass in the size of the window. In your code, you are passing in only the signal, without the size of the window.
If you manage to fix that problem, then you would then be passing the result of movmean() into sqrt(), and you would be passing 'window' as the second parameter to sqrt(). However, sqrt() does not accept any options at all.
The code you probably want would be
envelope = sqrt(movmean(rec_EMG.^2, window));
Muhammad Hadyan Utoro
Muhammad Hadyan Utoro il 17 Giu 2021
Thank you very much Mr. Robertson for the explanation. I put the bracket in the wrong position.
Appreciate your help

Accedi per commentare.


kumar maruthi srinivas chennu
Modificato: kumar maruthi srinivas chennu il 3 Set 2021
Can any one help me this please
function u = Anti_Tv(g,my,gamma)
gHS = uint8(imadjust (g));
gGC = uint8(255.*((double(g)./255).^(gamma)));
g = double(g(:));
n = length(g);
b = zeros(2*n,1);
d = b;
u = g;
eer = 1;k = 1;
tol = 1e-3;
Lambda = 0.05
[B, Bt, BtB] = DiffOper(sqrt(n));
Not enough input arguments
  2 Commenti
Walter Roberson
Walter Roberson il 3 Set 2021
What are you passing to the function?
You probably want uint8 not unit8
kumar maruthi srinivas chennu
Can you check this and let me know

Accedi per commentare.


sanjiv kumar
sanjiv kumar il 13 Ott 2021
Dear Matlab experts, If anyone one of you would like to assist me running the below code i would be really greatfule to you.
The error i am getting.
qardlecm
Not enough input arguments.
Error in qardlecm (line 24)
nn = size(data,1);
The code i want to run
....................................................................................................................................................................................................
%-------------------------------------------------------------------------%
% This procedure file provides the following outputs
% Short-run parameters (phi, theta) and its covariance matrix
% For this output, the following inputs are required
% 1) data : (n*(1+k)) matrix, where the 1st column is the dependent
% variable, and the last k columns are explanatory variables
% 2) ppp : p value of QARDL-ECM(p,q) model
% 3) qqq : q value of QARDL-ECM(p,q) model
% 4) tau : (s*1) vector of quantiles, which is sorted from the smallest to
% the largest.
% November 17, 2020
% Jin Seo Cho
%-------------------------------------------------------------------------%
function[bigphia,bigpia,thett,distthett] = qardlecm(data,ppp,qqq,tau)
nn = size(data,1);
k0 = size(data,2)-1;
ss = size(tau,1);
tau = sort(tau,1);
pd = makedist('normal','mu',0,'sigma',1);
za = icdf(pd,0.975);
hb = zeros(ss,1);
hs = zeros(ss,1);
for jj = 1:ss
hb(jj,1) = (4.5*normpdf(icdf(pd,tau(jj,1)))^4/(nn*(2*icdf(pd,tau(jj,1))^2+1)^2))^0.2;
hs(jj,1) = za^(2/3)*(1.5*normpdf(icdf(pd,tau(jj,1)))^2/(nn*(2*icdf(pd,tau(jj,1))^2+1)))^(1/3);
end
yy = data(:,1);
xx = data(:,2:size(data,2));
ee = xx(2:nn,:) - xx(1:(nn-1),:);
ee = [zeros(1,k0);ee];
eei = zeros(nn-qqq,qqq*k0);
xxi = xx(qqq+1:nn,:);
yyi = zeros(nn-ppp,ppp);
for jj = 1:k0
for ii = 0:qqq-1
eei(:, ii+1+(jj-1)*qqq) = ee((qqq+1-ii):(nn-ii),jj);
end
end
for ii = 1:ppp
yyi(:,ii) = yy((1+ppp-ii):(nn-ii),1);
end
if (ppp>qqq)
X = [eei((size(eei,1)+1-size(yyi,1)):size(eei,1),:), xxi((size(xxi,1)+1-size(yyi,1)):size(xxi,1),:), yyi];
else
X = [eei, xxi, yyi((size(yyi,1)+1-size(xxi,1)):size(yyi,1),:)];
end
ONEX = [ones(size(X,1),1),X];
Y = yy((nn-size(X,1)+1):nn,1);
bt = zeros(size(ONEX,2),ss);
fh = zeros(ss,1);
uu = zeros(nn-2,ss);
for jj = 1:ss
[bt1] = qregressMatlab(Y,ONEX,tau(jj,1));
uu(:,jj) = Y - ONEX*bt1;
fh(jj,1) = mean(normpdf(-uu(:,jj)/hb(jj,1)))/hb(jj,1);
bt(:,jj) = bt1;
end
barw = zeros(nn-1,qqq*k0);
for jj = 1:qqq
barw(jj:(nn-1),(k0*(jj-1)+1):k0*jj) = ee(2:(nn-jj+1),:);
end
tw = [ones(nn-1,1), barw];
mm = (xx((qqq+1):nn,:)'*xx((qqq+1):nn,:) - xx((qqq+1):nn,:)'*tw(qqq:(nn-1),:)*inv(tw(qqq:(nn-1),:)'*tw(qqq:(nn-1),:))*tw(qqq:(nn-1),:)'*xx((qqq+1):nn,:))/(nn-qqq)^2;
bb = zeros(ss,1);
for jj = 1:ss
bb(jj,1) = 1/((1-sum(bt(2+(qqq+1)*k0:1+(qqq+1)*k0+ppp,jj),1)')*fh(jj,1));
end
qq = zeros(ss,ss);
for jj = 1:ss
for ii = 1:ss
psu = zeros(2,1);
psu(1,1) = tau(jj,1);
psu(2,1) = tau(ii,1);
qq(jj,ii) = (min(psu,[],1)' - tau(jj,1)*tau(ii,1))*bb(jj,1)*bb(ii,1);
end
end
midbt = zeros(k0,ss);
for jj = 1:ss
midbt(:,jj) = bt(2+qqq*k0:1+(qqq+1)*k0,jj)/(1-sum(bt(2+(qqq+1)*k0:1+(qqq+1)*k0+ppp,jj),1)');
end
bigbt = reshape(midbt,[],1);
bigbtmm = kron(qq,inv(mm));
if (ppp>qqq)
yyj = zeros(nn-ppp,ppp);
xxj = zeros(nn-ppp,k0);
wwj = zeros(nn-ppp,qqq*k0);
for jj = 1:ppp
yyj(:,jj) = yy((ppp+1-jj):(nn-jj),1);
end
for ii = 1:k0
for jj = 1:qqq
wwj(:,jj+(ii-1)*qqq) = ee((ppp-jj+2):(nn-jj+1),ii);
end
end
xxj = xx((ppp+1):nn,:);
kk = zeros(nn-ppp,ss*ppp);
for jj = 1:ppp
Y = yyj(:,jj);
ONEX = [ones(nn-ppp,1),xxj,wwj];
for ii = 1:ss
[bbt] = qregressMatlab(Y,ONEX,tau(ii,1));
kkk = Y - ONEX*bbt;
kk(:,jj+(ii-1)*ppp) = kkk;
end
end
kka1 = kk(:,2);
kka2 = kk(:,4);
kka3 = kk(:,6);
kka = [kka1,kka2,kka3];
tilw = tw(ppp:(nn-1),:);
llla = (kka'*kka - kka'*tilw*inv(tilw'*tilw)*tilw'*kka)/(nn-ppp);
else
yyj = zeros(nn-qqq,ppp);
xxj = zeros(nn-qqq,k0);
wwj = zeros(nn-qqq,qqq*k0);
for jj = 1:ppp
yyj(:,jj) = yy((qqq+1-jj):(nn-jj),1);
end
for ii = 1:k0
for jj = 1:qqq
wwj(:,jj+(ii-1)*qqq) = ee((qqq-jj+2):(nn-jj+1),ii);
end
end
xxj = xx((qqq+1):nn,:);
kk = zeros(nn-qqq,ss*ppp);
for jj = 1:ppp
Y = yyj(:,jj);
ONEX = [ones(nn-qqq,1), xxj, wwj];
for ii = 1:ss
[bbt] = qregressMatlab(Y,ONEX,tau(jj,1));
kkk = Y - ONEX*bbt;
kk(:,jj+(ii-1)*ppp) = kkk;
end
end
kka1 = kk(:,2);
kka2 = kk(:,4);
kka3 = kk(:,6);
kka = [kka1,kka2,kka3];
tilw = tw(qqq:(nn-1),:);
llla = (kka'*kka - kka'*tilw*inv(tilw'*tilw)*tilw'*kka)/(nn-qqq);
end
cc = zeros(ss,ss);
for jj = 1:ss
for ii = 1:ss
psu = zeros(2,1);
psu(1,1) = tau(jj,1);
psu(2,1) = tau(ii,1);
cc(jj,ii) = (min(psu,[],1)' - tau(jj,1)*tau(ii,1))/(fh(ii,1)*fh(jj,1));
end
end
bigpia = zeros(ss*(ppp-1),ss*(ppp-1));
for jj = 1:ss
for ii = 1:ss
psu = inv(llla((jj-1)*(ppp-1)+1:jj*(ppp-1),(jj-1)*(ppp-1)+1:jj*(ppp-1)))*llla((jj-1)*(ppp-1)+1:jj*(ppp-1),(ii-1)*(ppp-1)+1:ii*(ppp-1))*inv(llla((ii-1)*(ppp-1)+1:ii*(ppp-1),(ii-1)*(ppp-1)+1:ii*(ppp-1)));
bigpia((jj-1)*(ppp-1)+1:jj*(ppp-1),(ii-1)*(ppp-1)+1:ii*(ppp-1)) = cc(jj,ii)*psu;
end
end
midphi = zeros(ppp,ss);
for jj = 1:ss
midphi(:,jj) = bt(2+(qqq+1)*k0:1+(qqq+1)*k0+ppp,jj);
end
bigphi = reshape(midphi,[],1);
bigphia1 = bigphi(2,1);
bigphia2 = bigphi(4,1);
bigphia3 = bigphi(6,1);
bigphia = [bigphia1; bigphia2; bigphia3];
dg = [nn^(1/2),0,0; 0,nn^(1/2),0; 0,0,nn];
uu2 = uu;
tilwb = tilw(:,2);
r1 = 1;
r2 = sum(tilwb,1)*(nn-2)^(-1);
r3 = sum(xx(3:nn,1),1)*(nn-2)^(-3/2);
r4 = r2;
rh5 = tilwb'*tilwb;
r5 = rh5*(nn-2)^(-1);
rh6 = tilwb'*xx(3:nn,1);
r6 = rh6*(nn-2)^(-3/2);
r7 = r3;
r8 = r6;
rh9 = xx(3:nn,1)'*xx(3:nn,1);
r9 = rh9*(nn-2)^(-2);
QQQ = [r1, r2, r3 ; r4, r5, r6; r7, r8, r9];
psiu = zeros(nn-2,3);
for jj = 1:3
for rr = 1:nn-2
if (uu2(rr,jj)<= 0)
psiu(rr,jj) = tau(jj,1)-1;
else
psiu(rr,jj) = tau(jj,1);
end
end
end
sigmma = psiu'*psiu*(1/(nn-2));
psiu1 = psiu(1:nn-2,1);
psiu2 = psiu(1:nn-2,2);
psiu3 = psiu(1:nn-2,3);
sium1 = mean(psiu1);
sium2 = mean(psiu2);
sium3 = mean(psiu3);
sigma1 = mean(psiu1.^(2));
sigma2 = mean(psiu2.^(2));
sigma3 = mean(psiu3.^(2));
distmt1 = nn*fh(1,1)^(-2)*sigmma(1,1)*inv(dg)*inv(QQQ)*inv(dg);
distmt2 = nn*fh(1,1)^(-1)*fh(2,1)^(-1)*sigmma(1,2)*inv(dg)*inv(QQQ)*inv(dg);
distmt3 = nn*fh(1,1)^(-1)*fh(3,1)^(-1)*sigmma(1,3)*inv(dg)*inv(QQQ)*inv(dg);
distmt4 = nn*fh(2,1)^(-1)*fh(1,1)^(-1)*sigmma(2,1)*inv(dg)*inv(QQQ)*inv(dg);
distmt5 = nn*fh(2,1)^(-2)*sigmma(2,2)*inv(dg)*inv(QQQ)*inv(dg);
distmt6 = nn*fh(2,1)^(-1)*fh(3,1)^(-1)*sigmma(2,3)*inv(dg)*inv(QQQ)*inv(dg);
distmt7 = nn*fh(3,1)^(-1)*fh(1,1)^(-1)*sigmma(3,1)*inv(dg)*inv(QQQ)*inv(dg);
distmt8 = nn*fh(3,1)^(-1)*fh(2,1)^(-1)*sigmma(3,2)*inv(dg)*inv(QQQ)*inv(dg);
distmt9 = nn*fh(3,1)^(-2)*sigmma(3,3)*inv(dg)*inv(QQQ)*inv(dg);
A11 = distmt1(2,2);
A12 = distmt1(3,3);
A13 = 2*distmt1(2,3);
A21 = distmt2(2,2);
A22 = distmt2(3,3);
A23 = 2*distmt2(2,3);
A31 = distmt3(2,2);
A32 = distmt3(3,3);
A33 = 2*distmt3(2,3);
A41 = distmt4(2,2);
A42 = distmt4(3,3);
A43 = 2*distmt4(2,3);
A51 = distmt5(2,2);
A52 = distmt5(3,3);
A53 = 2*distmt5(2,3);
A61 = distmt6(2,2);
A62 = distmt6(3,3);
A63 = 2*distmt6(2,3);
A71 = distmt7(2,2);
A72 = distmt7(3,3);
A73 = 2*distmt7(2,3);
A81 = distmt8(2,2);
A82 = distmt8(3,3);
A83 = 2*distmt8(2,3);
A91 = distmt9(2,2);
A92 = distmt9(3,3);
A93 = 2*distmt9(2,3);
distcon1 = A11 + A12 + A13;
distcon2 = A21 + A22 + A23;
distcon3 = A31 + A32 + A33;
distcon4 = A41 + A42 + A43;
distcon5 = A51 + A52 + A53;
distcon6 = A61 + A62 + A63;
distcon7 = A71 + A72 + A73;
distcon8 = A81 + A82 + A83;
distcon9 = A91 + A92 + A93;
distthett = [distcon1, distcon2, distcon3 ; distcon4, distcon5, distcon6 ; distcon7, distcon8, distcon9];
thett1 = bt(2,1) + bt(3,1);
thett2 = bt(2,2) + bt(3,2);
thett3 = bt(2,3) + bt(3,3);
thett = [thett1 ; thett2 ; thett3];
end
  1 Commento
Walter Roberson
Walter Roberson il 13 Ott 2021
When you press the green Run button, what is your expectation for where MATLAB should look for the value of the data ?

Accedi per commentare.


Ibrahim alkaltham
Ibrahim alkaltham il 14 Mar 2022
Modificato: DGM il 22 Feb 2023
I get Unrecognized function or variable 'theta'.
how to fix it
%**************************************************************************
% polar_dB(theta,rho,rmin,rmax,rticks,line_style)
%**************************************************************************
% POLAR_DB is a MATLAB function that plots 2-D patterns in
% polar coordinates where:
% 0 <= THETA (in degrees) <= 360
% -infinity < RHO (in dB) < +infinity
%
% Input Parameters Description
% ----------------------------
% - theta (in degrees) must be a row vector from 0 to 360 degrees
% - rho (in dB) must be a row vector
% - rmin (in dB) sets the minimum limit of the plot (e.g., -60 dB)
% - rmax (in dB) sets the maximum limit of the plot (e.g., 0 dB)
% - rticks is the # of radial ticks (or circles) desired. (e.g., 4)
% - linestyle is solid (e.g., '-') or dashed (e.g., '--')
%
% Credits:
% S. Bellofiore
% S. Georgakopoulos
% A. C. Polycarpou
% C. Wangsvick
% C. Bishop
%
% Tabulate your data accordingly, and call polar_dB to provide the
% 2-D polar plot
%
% Note: This function is different from the polar.m (provided by
% MATLAB) because RHO is given in dB, and it can be negative
%-----------------------------------------------------------------------------
function hpol =polar_dB(theta,rho,rmin,rmax,rticks,line_style)
% Convert degrees into radians
theta= theta* pi/180;
% Font size, font style and line width parameters
font_size = 16;
font_name = 'Times';
line_width = 1.5;
if nargin < 5
error('Requires 5 or 6 input arguments.')
elseif nargin == 5
if isstr(rho)
line_style = rho;
rho = theta;
[mr,nr] = size(rho);
if mr == 1
theta = 1:nr;
else
th = (1:mr)';
theta = th(:,ones(1,nr));
end
else
line_style = 'auto';
end
elseif nargin == 1
line_style = 'auto';
rho = theta;
[mr,nr] = size(rho);
if mr == 1
theta = 1:nr;
else
th = (1:mr)';
theta = th(:,ones(1,nr));
end
end
if isstr(theta) || isstr(rho)
error('Input arguments must be numeric.');
end
if any(size(theta) ~= size(rho))
error('THETA and RHO must be the same size.');
end
% get hold state
cax = newplot;
next = lower(get(cax,'NextPlot'));
hold_state = ishold;
% get x-axis text color so grid is in same color
tc = get(cax,'xcolor');
% Hold on to current Text defaults, reset them to the
% Axes' font attributes so tick marks use them.
fAngle = get(cax, 'DefaultTextFontAngle');
fName = get(cax, 'DefaultTextFontName');
fSize = get(cax, 'DefaultTextFontSize');
fWeight = get(cax, 'DefaultTextFontWeight');
set(cax, 'DefaultTextFontAngle', get(cax, 'FontAngle'), ...
'DefaultTextFontName', font_name, ...
'DefaultTextFontSize', font_size, ...
'DefaultTextFontWeight', get(cax, 'FontWeight') )
% only do grids if hold is off
if ~hold_state
% make a radial grid
hold on;
% v returns the axis limits
% changed the following line to let the y limits become negative
hhh=plot([0 max(theta(:))],[min(rho(:)) max(rho(:))]);
v = [get(cax,'xlim') get(cax,'ylim')];
ticks = length(get(cax,'ytick'));
delete(hhh);
% check radial limits (rticks)
if rticks > 5 % see if we can reduce the number
if rem(rticks,2) == 0
rticks = rticks/2;
elseif rem(rticks,3) == 0
rticks = rticks/3;
end
end
% define a circle
th = 0:pi/50:2*pi;
xunit = cos(th);
yunit = sin(th);
% now really force points on x/y axes to lie on them exactly
inds = 1:(length(th)-1)/4:length(th);
xunits(inds(2:2:4)) = zeros(2,1);
yunits(inds(1:2:5)) = zeros(3,1);
rinc = (rmax-rmin)/rticks;
% label r
% change the following line so that the unit circle is not multiplied
% by a negative number. Ditto for the text locations.
for i=(rmin+rinc):rinc:rmax
is = i - rmin;
plot(xunit*is,yunit*is,'-','color',tc,'linewidth',0.5);
text(0,is+rinc/20,[' ' num2str(i)],'verticalalignment','bottom' );
end
% plot spokes
th = (1:6)*2*pi/12;
cst = cos(th); snt = sin(th);
cs = [-cst; cst];
sn = [-snt; snt];
plot((rmax-rmin)*cs,(rmax-rmin)*sn,'-','color',tc,'linewidth',0.5);
% plot the ticks
george=(rmax-rmin)/30; % Length of the ticks
th2 = (0:36)*2*pi/72;
cst2 = cos(th2); snt2 = sin(th2);
cs2 = [(rmax-rmin-george)*cst2; (rmax-rmin)*cst2];
sn2 = [(rmax-rmin-george)*snt2; (rmax-rmin)*snt2];
plot(cs2,sn2,'-','color',tc,'linewidth',0.15); % 0.5
plot(-cs2,-sn2,'-','color',tc,'linewidth',0.15); % 0.5
% annotate spokes in degrees
% Changed the next line to make the spokes long enough
rt = 1.1*(rmax-rmin);
for i = 1:max(size(th))
text(rt*cst(i),rt*snt(i),int2str(abs(i*30-90)),'horizontalalignment','center' );
if i == max(size(th))
loc = int2str(90);
elseif i*30+90<=180
loc = int2str(i*30+90);
else
loc = int2str(180-(i*30+90-180));
end
text(-rt*cst(i),-rt*snt(i),loc,'horizontalalignment','center' );
end
% set viewto 2-D
view(0,90);
% set axis limits
% Changed the next line to scale things properly
axis((rmax-rmin)*[-1 1 -1.1 1.1]);
end
% Reset defaults.
set(cax, 'DefaultTextFontAngle', fAngle , ...
'DefaultTextFontName', font_name, ...
'DefaultTextFontSize', fSize, ...
'DefaultTextFontWeight', fWeight );
% transform data to Cartesian coordinates.
% changed the next line so negative rho are not plotted on the other side
for i = 1:length(rho)
if (rho(i) > rmin)
if theta(i)*180/pi >=0 && theta(i)*180/pi <=90
xx(i) = (rho(i)-rmin)*cos(pi/2-theta(i));
yy(i) = (rho(i)-rmin)*sin(pi/2-theta(i));
elseif theta(i)*180/pi >=90
xx(i) = (rho(i)-rmin)*cos(-theta(i)+pi/2);
yy(i) = (rho(i)-rmin)*sin(-theta(i)+pi/2);
elseif theta(i)*180/pi < 0
xx(i) = (rho(i)-rmin)*cos(abs(theta(i))+pi/2);
yy(i) = (rho(i)-rmin)*sin(abs(theta(i))+pi/2);
end
else
xx(i) = 0;
yy(i) = 0;
end
end
% plot data on top of grid
if strcmp(line_style,'auto')
q = plot(xx,yy);
else
q = plot(xx,yy,line_style);
end
if nargout > 0
hpol = q;
end
if ~hold_state
axis('equal');axis('off');
end
% reset hold state
if ~hold_state, set(cax,'NextPlot',next); end

Eirene Octavia
Eirene Octavia il 11 Lug 2022
Dear Matlab expert, please help me. My Matlab is 2016a, I try to run a code but there is an error "Not enough input arguments."
Error in astar (line 3)
ssNode = startNode;
function [ClosedList,cost,heuristic,func,iteration] = astar(source,target,weights,heuristics,startNode,goalNode)
%inisialisai starnode sebagai ssNode
ssNode = startNode;
%inisialisai goalNode sebagai ggNode
ggNode = goalNode;
%refactor semua variabel
%untuk mengurangi pemakaian memori
[s,t,n,sNode,gNode] = refactor(source,target,weights,sNode,ggNode);
%uniqeNodes merupakan semua node pada source dan target uniqueNodes = getNodes(s,t);
%keadaan awal open List
OpenList = [];
%initialisasi titik start
ClosedList = struct('Path' ,sNode,'Cost',0,'Heuristic',heuristics(sNode),'F',heuristics(sNode));
%masukan initial node kedalam antrian
OpenList = [OpenList ClosedList];
iteration = 1;
% lalukan pencarian hingga nsemua node telah dikunjungi
% atau tujuan ditemukan
while(isGoalReached(OpenList,gNode)==0 && ~isempty(OpenList)) [minI,minP] = minPath(OpenList);
OpenList(minI) = [];
%buat antrian baru
newPaths = getNewPaths(s,t,weights,heuristics,minP); OpenList = [OpenList newPaths];
% hitung jumlah perulangan iteration = iteration + 1;
end
if(~isempty(OpenList))
%masukan node dengan biaya terendah
%kedalam Closed list
[~,minP] = minPath(OpenList);
ClosedList = n(minP.Path);
cost = minP.Cost;
heuristic = minP.Heuristic;
func = minP.F;
else
ClosedList = [];
cost = [];
heuristic = [];
func = [];
end
end
%badingkan biaya setiap Node
function [minIndex,ClosedList] = minPath(paths)
minIndex = [];
ClosedList = [];
if(~isempty(paths))
minIndex = 1;
ClosedList = paths(minIndex);
if(length(paths)>1)
for i=2:length(paths)
if(paths(i).F < ClosedList.F)
minIndex = i;
ClosedList = paths(minIndex);
end
end
end
end
end
function isGoal = isGoalReached(paths,goalNode)
if(isempty(paths))
isGoal = 0;
return;
end
[~,minP] = minPath(paths);
if(minP.Path(length(minP.Path)) == goalNode)
isGoal = 1;
else
isGoal = 0;
end
end
function weight = getWeight(s,t,weights,nodeA,nodeB)
for i=1:length(s)
if(s(i)==nodeA && t(i)==nodeB)
weight = weights(i);
end
end
end
function paths = getNewPaths(s,t,w,h,path)
paths = [];
uniqueNodes = getNodes(s,t);
if(~isempty(path))
currentNode = path.Path(length(path.Path)); childs = getChilds(s,t,currentNode);
for i=1:length(childs)
% If path is not a loop
if(isempty(find(path.Path==childs(i), 1)))
c = path.Cost + getWeight(s,t,w,currentNode,childs(i));
heur = h(uniqueNodes==childs(i));
f = c + heur;
p = struct('Path',[path.Path childs(i)],'Cost',c,'Heuristic',heur,'F',f);
paths = [paths p];
end
end
end
end
function childs = getChilds(source,target,node)
childs = sort(target(source==node));
end
function nodes = getNodes(s,t)
nodes = unique(horzcat(s,t));
end
function [s,t,n,sn,gn] = refactor(source,target,~,startNode,goalNode)
sn = startNode;
gn = goalNode;
uNodes = unique(horzcat(source,target)); n = uNodes;
uNodes = unique(horzcat(source,target));
s = [];
t = [];
for i=1:length(source)
[~,sIndex] = ismember(source(i),uNodes);
[~,tIndex] = ismember(target(i),uNodes);
s = [s sIndex];
t = [t tIndex];
end
end
  3 Commenti
Steven Lord
Steven Lord il 11 Lug 2022
Based on how the astar function is defined:
function [ClosedList,cost,heuristic,func,iteration] = ...
astar(source,target,weights,heuristics,startNode,goalNode)
and from the fact that the third line of code uses the goalNode input argument:
ggNode = goalNode;
when you call astar you must call it with exactly six input arguments. If you call it with five or fewer inputs, you will receive an error when MATLAB tries to determine what should be assigned to the ggNode variable inside the function. If you try to call it with seven or more inputs, you will receive an error because MATLAB doesn't know what to do with that seventh input.
Eirene Octavia
Eirene Octavia il 12 Lug 2022
Thank you very much

Accedi per commentare.


Hussein Thary
Hussein Thary il 21 Giu 2023
Sol this programm
function I = Int(rho, z, t, fdphi)
global D lam alpha0 L0 Ep tau gamma M2 f w;
lam = 800e-9; % Wavelength in nm
w = 20.4e-6; % Beam radius on the focal plane in microns
f = 300e-3; % Focal length of the lens in mm
M2 = 2; % Beam quality factor
z0 = 0.815; % Rayleigh length in mm
n2 = 5e-15; % Nonlinear refractive index in cm^2/W
L = 1e-3; % Thickness of the nonlinear medium in mm
D = 200e-3; % Distance to the observation plane in mm
Ep = 20e-9; % Laser pulse energy in nJ
z = 10
% Additional parameters
alpha0 = 1 ./ L0; % Linear absorption coefficient (assuming constant)
tau = 25; % Pulse duration in fs
gamma = n2 * lam ./ (2 * pi); % Nonlinear refractive coefficient
% Calculations
k = 2 * pi / lam; % Wave number
w0 = (1e-3 * M2 * lam * f) ./ (pi * w); % Beam waist radius in mm
z0 = k * w0^2 / 2; % Rayleigh length in mm
wz = w0 * sqrt(1 + (z ./ z0)^2); % Beam radius at z coordinate
% Calculate wavefront curvature
Rz = z * (1 + (z0 / z)^2); % Radius of curvature of the wavefront
% Define radial coordinate
r = linspace(0, wz, 100); % Radial coordinate in mm
dr = r(2) - r(1);
% Calculate phase shift
dphi = zeros(size(r)) % Initialize phase shift
if fdphi == 1
Leff = L * (1 - exp(-alpha0 * L0)) / alpha0; % Effective length
dphi = k * Leff * gamma * Ep * 1e21 * exp(-2 * r.^2 ./ wz.^2) .* exp(-4 * log(2 * t^2 / tau^2)) ./ (1 + (z / z0)^2);
end
% Calculate the integrand
Iint = -r.^2 ./ wz.^2;
if z ~= 0
Iint = Iint - 1i * k * r.^2 / (2 * Rz);
end
Iint = Iint - 1i * dphi;
Iint = exp(Iint) .* r;
% Calculate the intensity for each rho
I = zeros(size(rho));
for m = 1:length(rho)
Isec = k * rho(m) * r / D;
Isec = besselj(0, Isec) .* Iint;
Isec = trapz(r, Isec) * dr;
Isec = abs(Isec);
I(m) = Isec^2;
end
% Intensity factor
Iprim = (4 * pi^2 * Ep) / (lam * D)^2 * (w0 / wz)^2 * exp(-alpha0 * L0);
if t ~= 0
Iprim = Iprim * exp(-4 * log(2) * t^2 / tau^2);
end
% Total Intensity
I = I * Iprim * 1e8;
% Plot the intensity distribution
plot(rho, I);
xlabel('Radial Coordinate (mm)');
ylabel('Intensity');
title('Far Field Intensity');
% Set the parameters based on the given conditions
lam = 500; % Wavelength in nm
w = 20.4; % Beam radius on the focal plane in microns
f = 300; % Focal length of the lens in mm
M2 = 2; % Beam quality factor
z0 = 0.815; % Rayleigh length in mm
n2 = 5e-15; % Nonlinear refractive index in cm^2/W
L = 1; % Thickness of the nonlinear medium in mm
D = 200; % Distance to the observation plane in mm
% Additional parameters
rho = linspace(-15/2, 15/2, 100); % Radial coordinate in mm
z = 10; % Z coordinate in mm
t = 25; % Time in fs
fdphi =10; % Flag for dphi calculation (1 = enabled)
% Plot the intensity distribution
figure;
plot(rho, I);
xlabel('Radial Coordinate (mm)');
ylabel('Intensity');
title('Far Field Intensity');
end

P
P il 4 Ott 2023
clear all
%Constants (all MKS, except energy which is in eV)
% hbar=1.055e-34;m=9.110e-31;epsil=8.854e-12;q=1.602e-19;
%Lattice
Np=100;a=le-10;X=a*[1:1:Np];t0=(hbar^2)/(2*m*(a^2))/q;L=a*(Np+1);
T=(2*t0*diag(ones(1,Np)))-(t0*diag(ones(1,Np-1),1))-(t0*diag(ones(1,Np-1),-1));
T(1,Np)=-t0;T(Np,1)=-t0;
[V,D]=eig(T);D=diag(D);[Enum,ind]=sort(D);
El=D(ind(1));psil=abs(V(:,ind(1)));P1=psil.*conj(psil);
E2=D(ind(50));psi2=abs(V(:,ind(50)));P2=psi2.*conj(psi2);
%analytical eigenvalues
Ean=(((hbar*pi)^2)/(2*m*(L^2))/q)*[1:Np].*[1:Np];
hold on
h=plot(Enum,'bx');
set(h,'linewidth',[3.0])
set(gca,'Fontsize',[25])
xlabel(' Eigenvalue Number,alpha-->');
ylabel('E(eV)--->');
grid on
  1 Commento
Walter Roberson
Walter Roberson il 4 Ott 2023
The constants are commented out, so it is going to search for hbar as a function

Accedi per commentare.

Categorie

Scopri di più su Functions in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by