MATLAB: How to use IF with @(block_struct) function

blockprocimage processing

fun2 = @(block_struct) ...
if block_struct.data < 100
std2(block_struct.data) * (block_struct.data));
end
Doesnt work.
I actually want to manipulate individual elements of my block
blocks made of 8×8 values ranging from 0-255

Best Answer

Hi Saud,
Since blockproc uses anonymous functions, you may save your multi-line function into a script, say myFunc.m and then pass @myFunc to your blockproc call.
You can find block_struct structure described in the following doc (under More About section): 'blockproc' Documentation.
You may work out a way to manage the sequence artificially using some of those fields. For example, using block_struct.location to skip processing the 2nd block:
function out = myFunc(block_struct) % size would be 100x100
if(block_struct.location(2)==101)
% skipping the 2nd block.
out = block_struct.data;
else
% code for processing every other element
end
end
Hope it helps!