MATLAB Answers

Not Enough Input Arguments

조회 수: 7,377(최근 30일)
TheLimpNinja
TheLimpNinja 2012년 11월 7일
편집: Davi Pramana Putra 약 18시간 전
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.
  댓글 수: 9
Walter Roberson
Walter Roberson 2019년 10월 7일
Line 38 of which function?

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

채택된 답변

Akiva Gordon
Akiva Gordon 2012년 11월 8일
편집: MathWorks Support Team 2018년 11월 27일
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.
  댓글 수: 5
Evan Curatolo
Evan Curatolo 2020년 9월 27일
Oh man. Bless your soul. Thank you for this comment.

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

추가 답변(17개)

TheLimpNinja
TheLimpNinja 2012년 11월 7일
편집: Walter Roberson 2016년 7월 15일
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
Steven Lord
Steven Lord 2016년 12월 27일
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.]

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


TheLimpNinja
TheLimpNinja 2012년 11월 7일
편집: Walter Roberson 2012년 11월 7일
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
Waldemiro Kubucama
Waldemiro Kubucama 2020년 8월 1일
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.

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


Brian Batson
Brian Batson 2012년 11월 29일
편집: Brian Batson 2012년 11월 29일
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
Walter Roberson
Walter Roberson 2020년 3월 29일
https://www.mathworks.com/matlabcentral/answers/53100-not-enough-input-arguments#comment_109973

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


Annie micheal
Annie micheal 2016년 7월 15일
편집: Walter Roberson 2016년 7월 15일
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
Walter Roberson
Walter Roberson 2016년 7월 15일
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.

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


REEMA MOHANTY
REEMA MOHANTY 2016년 12월 27일
편집: Walter Roberson 2017년 5월 26일
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 2017년 3월 3일
편집: Walter Roberson 2017년 3월 3일
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
Steven Lord
Steven Lord 2017년 3월 24일
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.

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


Ganesh Petkar
Ganesh Petkar 2017년 4월 18일
I am getting error for below function as "Not enough input arguments. "
delayed_signal = mtapped_delay_fcn(input);
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 4월 18일
input is a MATLAB function call. See https://www.mathworks.com/help/matlab/ref/input.html

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


Wendell
Wendell 2017년 5월 26일
편집: Walter Roberson 2017년 5월 26일
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
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 5월 26일
Please read the previous Answers here.

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


aarthy reddy R
aarthy reddy R 2019년 9월 4일
편집: Walter Roberson 2019년 10월 14일
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
Walter Roberson
Walter Roberson 2019년 10월 14일
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...

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


Chapat
Chapat 2020년 3월 11일
편집: Walter Roberson 2020년 3월 11일
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
Walter Roberson
Walter Roberson 2020년 3월 11일
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.

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


Josilyn Dostal
Josilyn Dostal 2020년 4월 23일
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
Josilyn Dostal
Josilyn Dostal 2020년 4월 24일
You are my savior. Youre so nice.

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


Maria hassan
Maria hassan 2020년 7월 13일
Hi,
I am getting error 'Not enough input arguments.' I am trying online trail oversion. When I click run icon, it does not allow me to enter the value for the input as there is no option for entering the values. Any advice here please?
Best
Sarah

Gurwinder pal singh Bhinder
Gurwinder pal singh Bhinder 2020년 11월 27일
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
Walter Roberson
Walter Roberson 2020년 11월 27일
Right.

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


Muhammad Hadyan Utoro
Muhammad Hadyan Utoro 2021년 6월 17일
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
Muhammad Hadyan Utoro
Muhammad Hadyan Utoro 2021년 6월 17일
Thank you very much Mr. Robertson for the explanation. I put the bracket in the wrong position.
Appreciate your help

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


kumar maruthi srinivas chennu
kumar maruthi srinivas chennu 2021년 9월 3일
편집: kumar maruthi srinivas chennu 2021년 9월 3일
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
kumar maruthi srinivas chennu
kumar maruthi srinivas chennu 2021년 9월 3일
Can you check this and let me know

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


sanjiv kumar
sanjiv kumar 2021년 10월 13일 5:45
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
Walter Roberson
Walter Roberson 2021년 10월 13일 8:01
When you press the green Run button, what is your expectation for where MATLAB should look for the value of the data ?

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


Davi Pramana Putra
Davi Pramana Putra 약 18시간 전
편집: Davi Pramana Putra 약 18시간 전
My code error: Not enough input arguments.
[a1,b1]=find(Key==IV);(line 13)
% Using Image Encryption Playfair cipher
function [Imagekey]=PlayfairCipher(ImageOpen,Key) %ImageOpen:Plain Image ImageKey: Ciphertext Image
[namefile,formatfile] = uigetfile({'*.jpg;*.png;*.bmp'}, 'choose images');
ImageOpen = imread([formatfile,namefile]);
[m2,n2,o1]=size(ImageOpen);
Imagekey=ImageOpen;
for k=1:o1
for i=1:m2
for j=1:2:n2
IV=Imagekey(i,j,k);
IH=Imagekey(i,j+1,k);
[a1,b1]=find(Key==IV); %Why code error?
[a2,b2]=find(Key==IH);
if IV~=IH
if a1==a2 %if same rows in playfair cipher
Imagekey(i,j,k)=Key(a1,mod(b1,16)+1);
Imagekey(i,j+1,k)=Key(a2,mod(b2,16)+1);
elseif b1==b2 %if same columns in playfair cipher
Imagekey(i,j,k)=Key(mod(b1,16)+1,b1);
Imagekey(i,j+1,k)=Key(mod(b2,16)+1,b2);
else %if are not same rows or columns in playfair cipher
Imagekey
Key
Imagekey(i,j,k)=Key(a1,b2);
Imagekey(i,j+1,k)=Key(a2,b1);
end
end
end
end
end
I didn't understand this error, how to solve this code error ?

태그

Community Treasure Hunt

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

Start Hunting!

Translated by