Effacer les filtres
Effacer les filtres

problem with dividing matrix into subblocks using blockproc and global varaible!

3 vues (au cours des 30 derniers jours)
wissam
wissam le 25 Avr 2014
Commenté : Geoff Hayes le 26 Avr 2014
Dear All, I want to divide a 3 by 15 matrix into 3 by 3 blocks (no overlap) blockproc. I use global variables to extract those blocks. Please have a look at this code shown below:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function test()
global all_blocks item
item=0; all_blocks=[];
x=rand(3,15)
fun = @(block_struct) block1(block_struct.data);
y = blockproc(x,[3 3],fun,'BorderSize',[0 0],...
'TrimBorder',true,'PadPartialBlocks',true);
z=all_blocks
end
function output= block1(in_array)
global all_blocks item
output=in_array;
item=item+1;
all_blocks{item}=in_array;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
the output of this code, z, is a 1 by 8 cells whereas the true output is 1 by 5 cells !. The cell no. 8, 7, and 6 of z are repeated (extra blocks). I do not want to use other functions such as mat2cell. Any suggestion why the output is like that?.. many thanks, wissam
  3 commentaires
wissam
wissam le 26 Avr 2014
Dear Geoff, many thanks for the valuable feedback. Yes, I traced the code using breakpoints and I found that, blockproc produces some repeated blocks (cell no. 8, 7, and 6). I don't know what the problem is.
regarding your code, It works very fine and thank you for that. How about if there is an overlap of 50% among blocks? is it possible to modify your code to extracted overlapped blocks?
best regards
Geoff Hayes
Geoff Hayes le 26 Avr 2014
I suspect that it will be relatively easy to add a 50% overlap…I will leave that for you though! :)

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by