The left and right sides have a different number of elements

3 views (last 30 days)
please help me fix the error~~~
this is my code and
%% 3. Fourier descriptor
%① Make the matrix above.
%Find the positions (x1, x2) of foreground pixels valued '1' and save them to ‘pos’ array.
input=[0 0 0 0 0 0 0; 0 0 0 1 0 0 0; 0 0 1 0 1 0 0; 0 1 0 0 0 1 0; 0 0 1 0 1 0 0; 0 0 0 1 0 0 0; 0 0 0 0 0 0 0];
pos=boundary4(input);
%② Make a vector ‘comp’ that contains complex numbers:
%real value: x1 of an element of ‘pos’,imaginary value: x2 of an element of ‘pos’.
comp=complex(pos(:,1),pos(:,2));
%③ Do Fourier transform with ‘comp’ and save the result to ‘ft’.
ft=fft(comp);
%Make zero vector ‘ft1’ which has same size of ‘ft’ and save only first and second element value of ‘ft’ to ‘ft’1.
ft1=zeros(size(ft));
ft1(1:2) =ft(1:2);
%④ Do inverse transform of ‘ft1’ and display the results by plotting imaginary numbers.
figure
subplot(1,2,1);
plot(input), axis ([1,14,1,14]), axis square
title('input');
subplot(1,2,2);
plot(ifft (ft1),'o'), axis ([1,14,1,14]), axis square
title('output');
this is the fxn to get the boundary
function out=boundary4(image)
n=[0 1;-1 0;0 -1;1 0];
flag=1;
cc=[];
[x,y]=find(image==1);
x=min(x);
imx=image(x,:);
y=min(find(imx==1));
first=[x y];
dir=3;
while flag==1
tt=zeros(1,4);
newdir=mod(dir+3,4);
for i=0:3
j=mod(newdir+i,4)+1;
tt(i+1)=image(x+n(j,1),y+n(j,2));
end
d=min(find(tt==1));
dir=mod(newdir+d-1,4);
x=x+n(dir+1,1);y=y+n(dir+1,2);
cc=[cc;x y];
if x==first(1)&y==first(2)
flag=0;
end
end
out =cc;
and i get this error
Unable to perform assignment because the left and right sides have a different number of elements.
Error in boundary4 (line 19)
tt(i+1)=image(x+n(j,1),y+n(j,2));
Error in script (line 57)
pos=boundary4(input);

Answers (1)

VBBV
VBBV on 30 Nov 2021
Edited: VBBV on 30 Nov 2021
tt(:,i+1)=image(x+n(j,1),y+n(j,2))
Change this line to above

Categories

Find more on Live Scripts and Functions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by