# why do i get this error as no enough input arguments

1 view (last 30 days)
sanket neharkar on 16 Nov 2022
Answered: Image Analyst on 17 Nov 2022
function [J,distinct_d]=jd(X,p)
% Computes the distances between all pairs of points in a sampling
% plan X using the p–norm, sorts them in ascending order and
% removes multiple occurrences.
%
% Inputs:
% X – sampling plan being evaluated
% p – distance norm (p=1 rectangular – default, p=2 Euclidean)
%
% Outputs:
% J – multiplicity array (that is, the number of pairs
% separated by each distance value).
% distinct_d – list of distinct distance values
if ~exist('p','var')
p=1;
end
% Number of points in the sampling plan
n=size(X,1);
% Compute the distances between all pairs of points
d=zeros(1,n*(n-1)/2);
for i=1:n-1
for j=i+1:n
% Distance metric: p–norm
d((i-1)*n-(i-1)*i/2+j-i)=norm(X(i,:)-X(j,:),p);
end
end
% Remove multiple occurrences
distinct_d=unique(d);
% Pre-allocate memory for J
J =zeros(size(distinct_d));
% Generate multiplicity array
for i=1:length(distinct_d)
% J(i) will contain the number of pairs separated
% by the distance distinct_d(i)
J(i)=sum(ismember(d,distinct_d(i)));
end
after this wheni am running this code i am gettimg a error as no enough arguments
this code i have taken from a book

Image Analyst on 17 Nov 2022
You can't just push the green run triangle because it won't know what you want for the input arguments. You have to either
1. call the function with a script or function in another m-file, or
2. call it in a script defined before the function in the same m-file. In this case the function will have to have "end" as the last line.

Askic V on 16 Nov 2022
Edited: Askic V on 16 Nov 2022
You're probably executing this code as a Matlab script. You need to make a function call.
This code should be saved in a separate file called jd.m.
and in Matlab command windows make a coll of this function, like:
[j_out,d_out] = jd(X,1)

Kevin Holly on 16 Nov 2022
I just ran the code without getting an error.
x = 10*rand(4,2)
x = 4×2
9.1847 5.8076 4.9108 6.3358 3.5890 2.8121 4.7894 9.1143
[J,distinct_d] = jd(x,1)
J = 1×6
1 1 1 1 1 1
distinct_d = 1×6
2.8999 4.8020 4.8455 7.5026 7.7020 8.5911
function [J,distinct_d]=jd(X,p)
% Computes the distances between all pairs of points in a sampling
% plan X using the p–norm, sorts them in ascending order and
% removes multiple occurrences.
%
% Inputs:
% X – sampling plan being evaluated
% p – distance norm (p=1 rectangular – default, p=2 Euclidean)
%
% Outputs:
% J – multiplicity array (that is, the number of pairs
% separated by each distance value).
% distinct_d – list of distinct distance values
if ~exist('p','var')
p=1;
end
% Number of points in the sampling plan
n=size(X,1);
% Compute the distances between all pairs of points
d=zeros(1,n*(n-1)/2);
for i=1:n-1
for j=i+1:n
% Distance metric: p–norm
d((i-1)*n-(i-1)*i/2+j-i)=norm(X(i,:)-X(j,:),p);
end
end
% Remove multiple occurrences
distinct_d=unique(d);
% Pre-allocate memory for J
J =zeros(size(distinct_d));
% Generate multiplicity array
for i=1:length(distinct_d)
% J(i) will contain the number of pairs separated
% by the distance distinct_d(i)
J(i)=sum(ismember(d,distinct_d(i)));
end
end

### Categories

Find more on Logical in Help Center and File Exchange

R2020b

### Community Treasure Hunt

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

Start Hunting!