problem with dividing matrix into subblocks using blockproc and global varaible!
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Geoff Hayes
am 26 Apr. 2014
I suspect that it will be relatively easy to add a 50% overlap…I will leave that for you though! :)
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!