Error & returning a set of values

조회 수: 2 (최근 30일)
med-sweng
med-sweng 2013년 2월 13일
I have the `test` function shown below written in `matlab`, and underneath the `test` function you can find other functions that the `test` function uses.
Here, I have two points:
*1- When I run the program, I get the following error. Why is that? How can I solve it?*
??? Input argument "y" is undefined.
Error in ==> relative_complement at 2
rl = setdiff(x,y);
Error in ==> test at 44
rl = relative_complement(support, C.(sprintf('Ck')));
*2- As an output, I want the values of `C.(sprintf('Ck'))` to be produced as a set of values rather than only one value. In other words, for each iteration to update the value of `Ck` and get the result as a set. How can I do that?*
*test*
function test
F = [5 3 3 4 ; 5 3 2 4; 6 5 3 6; 6 4 3 3; 8 4 3 6; 7 5 4 3; 87 5 4 3];
support = [1 3 4 4; 5 4 4 6; 6 5 43 3; 7 4 3 4];
C = struct;
n=10;
for i=1:n
C.(sprintf('C%d',i)) = [];
end
C.(sprintf('Ck')) = [];
k=0;
while k<n
rl = relative_complement(support, C.(sprintf('Ck')));
pixels = belongs_to(F, rl);
d = equalize_dimension(F, pixels);
e = pixel_minimize_distance(d.x, d.y);
C.(sprintf('Ck')) = e;
C.(sprintf('Cnew')) = C.(sprintf('Ck'));
d1 = equalize_dimension(F, C.(sprintf('Cnew')));
d2 = equalize_dimension(F, C.(sprintf('C%d',k+1)));
distance_new = distance_between_sets(d1.x, d1.y);
distance_k_plus_one = distance_between_sets(d2.x, d2.y);
if isempty(C.(sprintf('C%d',k+1))) | distance_new < distance_k_plus_one
C.(sprintf('C%d',k+1)) = C.(sprintf('Cnew'));
C.(sprintf('Ck')) = C.(sprintf('C%d',k+1));
end
end
C.(sprintf('Ck'))
end
*relative_complement*
function rl = relative_complement(obj,x,y)
rl = setdiff(x,y);
end
belongs_to**
function p = belongs_to(x,y)
member = ismember(x,y);
p = x(member==1);
end
equalize_dimension**
function n = equalize_dimension (x,y)
[r1 c1] = size(x);
[r2 c2] = size(y);
if r1<r2
e= r2-r1;
for i=1:e
x(r1+1,1)=0;
r1 = r1 + 1;
end
[r1 c1] = size(x);
n.x =x;
n.y = y;
end
if r1>r2
e = r1-r2;
for i=1:e
y(r2+1,1)=0;
r2 = r2 + 1;
end
[r2 c2] = size(y);
n.x = x;
n.y = y;
end
if c1<c2
e= c2-c1;
for i=1:e
x(1,c1+1)=0;
c1 = c1 + 1;
end
[r1 c1] = size(x);
n.x = x;
n.y = y;
end
if c1>c2
e = c1-c2;
for i=1:e
y(1,c2+1)=0;
c2 = c2 + 1;
end
[r2 c2] = size(y);
n.x = x;
n.y = y;
end
if r1==r2 && c1==c2
n.x = x;
n.y = y;
end
end
*pixel_minimize_distance*
function m = pixel_minimize_distance(x,y)
maximum = (sum(sum(pdist2(x,y))));
[r c] = size(y);
initialValue = y(1,1);
for i=1:r
for j=1:c
o = y(i,j);
y(i,j) = 0;
sum2 = (sum(sum(pdist2(x,y))));
if sum2 >= maximum
if o ~= 0
maximum = sum2;
m = o;
end
maximum = maximum;
m = initialValue;
end
y(i,j)=o;
end
end
end
distance_between_sets**
function m = distance_between_sets(x,y)
[r c] = size(x);
for i=1:r
for j=1:c
summation = (sum(sum(pdist2(x,y))));
end
end
m=summation;
end
Thanks.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by