Accessing elements of a block

조회 수: 6 (최근 30일)
Monisha
Monisha 2012년 6월 26일
Please help me soon with this! Thanks a ton!
I need to divide an image of size 72x72 into 64 blocks of size 9x9 each. Then, I need to perform some sort of processing on each block by accessing each value within each block. Should I use blockproc or mat2cell? How do I access each element within a block? If I use blockproc, how do I use the third parameter to create my own function that will be called for each block?
The following code threw this error
??? Cell contents reference from a non-cell array object.
Error in ==> module2 at 21 x=myCell{1,1}{j,k};
[final_img]=module1;
myCell = mat2cell(final_img,[9 9 9 9 9 9 9 9], [9 9 9 9 9 9 9 9]);
% C={myCell};
y=1; %initial previous value
w=1;
o=1; %o-output vector index
p=1;
rx = zeros(64,1);
ry = zeros(64,1);
rx(1)=0;
ry(1)=0;
for i=1:8
for l=1:8
[m,n]=size(myCell{1,1}); %m-rows n-column m=n=9
for j=1:m
for k=1:n
x=myCell{1,1}{j,k};
z=myCell{1,1}{k,j};
if x~=y %compare with previous value
rx(o)=rx(o)+1; %horizontalcount++
end
if z~=w
ry(p)=ry(p)+1; %verticalcount++
end
y=x;
w=z;
end
end
end
o=o+1;
p=p+1;
end
So, how do I get the value of x and z?

채택된 답변

Walter Roberson
Walter Roberson 2012년 6월 26일
All of your myCell{1,1} should instead be myCell{i,l} and the indexing after that should be in () instead of in {}
myCell{i,l}(j,k)
  댓글 수: 3
Walter Roberson
Walter Roberson 2012년 6월 26일
Your "y" and "w" do not change at all, so you are not comparing against the "previous" values, only against fixed values.
Monisha
Monisha 2012년 6월 26일
wait! wait! I think I found the error...
the incrementing of the variables o and p have been put in the wrong place! It works now!
So the code looks like this now. Are you sure abt the y and w not changing on each iteration?
[final_img]=module1;
myCell = mat2cell(final_img,[9 9 9 9 9 9 9 9], [9 9 9 9 9 9 9 9]);
y=1; %initial previous value
w=1;
o=1; %o-output vector index
p=1;
rx = zeros(64,1);
ry = zeros(64,1);
rx(1)=0;
ry(1)=0;
for i=1:8
for l=1:8
[m,n]=size(myCell{i,l}); %m-rows n-column m=n=9
for j=1:m
for k=1:n
x=myCell{i,l}(j,k);
z=myCell{i,l}(k,j);
if x~=y %compare with previous value
rx(o)=rx(o)+1; %horizontalcount++
end
if z~=w
ry(p)=ry(p)+1; %verticalcount++
end
y=x;
w=z;
end
end
o=o+1;
p=p+1;
end
end

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by