Accessing elements of a block
    4 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
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?
0 Kommentare
Akzeptierte Antwort
  Walter Roberson
      
      
 am 26 Jun. 2012
        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 Kommentare
  Walter Roberson
      
      
 am 26 Jun. 2012
				Your "y" and "w" do not change at all, so you are not comparing against the "previous" values, only against fixed values.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

