Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Topic: Error and handling output (returning a set of values)
Replies: 1   Last Post: Feb 13, 2013 1:25 PM

 Messages: [ Previous | Next ]
 Abder-Rahman Posts: 122 Registered: 7/4/08
Error and handling output (returning a set of values)
Posted: Feb 13, 2013 9:57 AM

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.

Date Subject Author
2/13/13 Abder-Rahman
2/13/13 dpb