problem with dividing matrix into subblocks using blockproc and global varaible!
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Geoff Hayes
2014 年 4 月 26 日
I suspect that it will be relatively easy to add a 50% overlap…I will leave that for you though! :)
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!